answersLogoWhite

0

/* ellipses (...) used to represent tabs for clarity */

int array[N]; /* N must be contant literal in this example */

bubblesort (int *a, int n) {
... int swap = 1;
... while (swap) {
... ... int i;
... ... int temp;
... ... swap = 0;
... ... for (i=0; i < n-2; i++) {
... ... ... if (a[i] > a[i+1]) {
... ... ... ... swap = 1;
... ... ... ... temp = a[i];
... ... ... ... a[i] = a[i+1];
... ... ... ... a[i+1] = temp;
... ... ... }
... ... }
... ... n--;
... }
}

/* fill the array with some data */

bubblesort (a, N);

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

In the bubble sort algorithm the second loop iterates ---------- for each of the unsorted array elements?

n-1 times


What Program that lists telephone numbers in numeric order or street address?

In programming this could be achieved using a numeric bubble sort. Excel allows this type of sorting to be used.


How many key comparison and interchanges are required to sort a file of size n using bubble sort?

rfsghdfhdh


What is another name for bubble sort?

Bubble sort is also known as sinking sort.


How do write sorting of numbers using microprocessor?

There are several methods available to sort numbers. A simple way to program sorting is the so-called "bubble-sort". This is inefficient for larger lists of numbers; in which case it is more convenient to use one of the faster algorithms, for example, "quick-sort".


Program to print sorting of an array in clanguage?

/* PROGRAM TO SORT ARRAY ELEMENTS USING BUBBLE SORT*/ #include #include void main() { int i,j,n,t,a[50]; clrscr(); printf("ENTER THE ARRAY SIZE:\n"); scanf("%d",&amp;n); printf("ENTER THE ARRAY ELEMENTS:\n"); for(i=0;i


Is bubble sort a stable sorting algorithm?

Yes, bubble sort is a stable sorting algorithm.


What is the C program for heap sort using recursion?

123


Which sorting algorithm is more efficient for small datasets: bubble sort or selection sort?

Selection sort is more efficient for small datasets compared to bubble sort.


Why is Bubble Sort considered to have a time complexity of O(n2)?

Bubble Sort is considered to have a time complexity of O(n2) because it compares each element in the list with every other element, resulting in a nested loop structure that requires n iterations for each of the n elements in the list, leading to a quadratic time complexity.


Why is the bubble sort technique is popular?

Because it is so simple. It is also inefficient, but for small data sets there is no need to be more complex, unless you are doing it many, many times in a tight loop.


Who invented the bubble sort?

ramesh