bubble sorting array in c

Solutions on MaxInterview for bubble sorting array in c by the best coders in the world

showing results for - "bubble sorting array in c"
Jessica
14 Jul 2016
1/* Bubble sort code in C */
2#include <stdio.h>
3
4int main()
5{
6  int array[100], n, c, d, swap;
7
8  printf("Enter number of elements\n");
9  scanf("%d", &n);
10
11  printf("Enter %d integers\n", n);
12
13  for (c = 0; c < n; c++)
14    scanf("%d", &array[c]);
15
16  for (c = 0 ; c < n - 1; c++)
17  {
18    for (d = 0 ; d < n - c - 1; d++)
19    {
20      if (array[d] > array[d+1]) /* For decreasing order use '<' instead of '>' */
21      {
22        swap       = array[d];
23        array[d]   = array[d+1];
24        array[d+1] = swap;
25      }
26    }
27  }
28
29  printf("Sorted list in ascending order:\n");
30
31  for (c = 0; c < n; c++)
32     printf("%d\n", array[c]);
33
34  return 0;
35}
36
37
Anton
29 Feb 2019
1#include <bits/stdc++.h> 
2using namespace std; 
3  
4void swap(int *xp, int *yp)  
5{  
6    int temp = *xp;  
7    *xp = *yp;  
8    *yp = temp;  
9}  
10  
11// A function to implement bubble sort  
12void bubbleSort(int arr[], int n)  
13{  
14    int i, j;  
15    for (i = 0; i < n-1; i++)      
16      
17    // Last i elements are already in place  
18    for (j = 0; j < n-i-1; j++)  
19        if (arr[j] > arr[j+1])  
20            swap(&arr[j], &arr[j+1]);  
21}  
22  
23/* Function to print an array */
24void printArray(int arr[], int size)  
25{  
26    int i;  
27    for (i = 0; i < size; i++)  
28        cout << arr[i] << " ";  
29    cout << endl;  
30}  
31  
32// Driver code  
33int main()  
34{  
35    int arr[] = {64, 34, 25, 12, 22, 11, 90};  
36    int n = sizeof(arr)/sizeof(arr[0]);  
37    bubbleSort(arr, n);  
38    cout<<"Sorted array: \n";  
39    printArray(arr, n);  
40    return 0;  
41}
queries leading to this page
bubble sort explainedbubble sorting in c programmingprogram to show each step in bubble sort processbubble sort c programbubble sort in c codebubble sort implementation in cbubble sort arraybubble sort in c 5cbuble sort in cbubble sorting array elments in increasing order in cbubble sort in c using function and array with stringsbubble sorting in array in cbubble sort code in che was asked to implement bubble sortbubble sort using cbubble sort program in csorting codebubbleshort in cbubble sort algorithm explanation in cc program for bubble sortbubble sort algorithm c in c bubble sortc 2b 2b bubble sortwrite a c program to find the bubble sort stepsbubble sort in c programbubble program in cbubble sorting cbubble sort for cbubble sort codebubble sort algorithm in c with examplebubble sort algorithm in cin c bubble sortbuble sort for cbubllle sort codebubble sort cimplement bubble sort in cbubble sort algorithm c 2b 2bbubblesort codebubble sorting in cbublble sort in ccode for the bubble sort algorithmimplementing bubble sort in cbable sort arraybubble sort in program cbubble sort c 2b 2bbubble sorting program in cbubble sort descending order in cbubble sort in c languagebubble sort output placec function for bubble sortbuuble sort cbubble sort numbersc bubble sortbubble sort in c ascending ordersorting 3a bubble sortbubble sort algorithm in c the simplestbubble sort in c what is nbubble sort c code examplebubble sort functionsimple bubble sort program in cbubblesort c 2b 2bbubble sort algorithm code in cbubble short sumsarray to test bubble sortbubble sort for strings in c without string functionsbubble sor in cc program for bubble sortinbuble short in cbubble sort for array in cbubble sortingsorting using bubble sort in cbubble sort algoritmo chow to use bubble sort in cbubble sort code using function in cbubble sort program cbubble sort program c 2b 2bbubble in cbubble sort in c sort in cbuble sort codebubble sorting algorithmwhat is bubble sort in cbubble sort in descending order chow to bubble dort an array in cbubble sort passwise output examplebubble sort examplea function that uses bubble sort to sort an array from smallest to largestinterchange sort in system programmingbubble sort site 3ageeksforgeeks orgbubble sorting an array in cuse bubble sort in cbubble sort in cbuble sort carray of structures bubble sort chow to do bubble sort in cbubble sort c descending orderbubble sort search in cbubble sort function in cimplementation of bubble sort in cbuble sort coding example in cbubble sort c examplebubble sort in o 28n 29sorting an array using bubble sort algorithmbubblesort cc program for bubble sortingc in bubblebubble sort in cbubble sort codebubblesort in calgorithm of bubble sorting in chbubble sort c 2b 2bbubble sort in c on tructurec bubblesortbubble sorting array in cbubble sort program in c using functionbubble sort for strings in cbubble cbubble sory arraybubble sort algorithm in cc code for bubble sortbubble sort c codebubble sort en cbubble sorting array in c