answersLogoWhite

0


Best Answer

Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, it is not efficient for sorting large lists; other algorithms are better.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

#include <stdio.h>

int main()

{

int array[100], n, i, j, temp;

printf("Enter number of elements\n");

scanf("%d", &n);

printf("Enter %d integers\n", n);

for (i = 0; i < n; i++)

scanf("%d", &array[i]);

for (i = 0 ; i < ( n - 1 ); i++)

{

for (j = 0 ; j < n - i - 1; j++)

{

if (array[j] > array[j+1]) /* For decreasing order use < */

{

temp = array[j];

array[j] = array[j+1];

array[j+1] = temp;

}

}

}

printf("Sorted list in ascending order:\n");

for ( i = 0 ; i < n ; i++ )

printf("%d\n", array[i]);

return 0;

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

Theory of Algorithms

15-01-2004

Heapsort - Sebastian Streich, Enric Meinhardt 8

Subroutines for Heaps

Heapify(A,i)

l := largest node of i and its children

if ( i ≠ l )

exchange A[i] with A[l]

Heapify(A, l)

A real implementation should not be recursive!

(overhead when passing the function's arguments)

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

for(i=0;i<size;i++)

{

flag=0;

for(j=0;j<size-i-1;j++)

{

if(a[j]>a[j+1])

{

flag=1;

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

if(flag==0)

break;

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

using System.Linq;

myArray.OrderBy(s=>s).ToArray();

or

myArray.OrderByDescending(s=>s).ToArray();

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you do bubble sort in C programming?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Different types of sorting techniques in c language?

types of sorting in c language are: insertion sort selection sort bubble sort merge sort two way merge sort heap sort quick sort


What is another name for bubble sort?

Bubble sort is also known as sinking sort.


What is sort in C programming pls ans. this... thanks?

There is a built-in qsort function, see stdlib.h


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.


Is quick sort is an example of dynamic programming algorithm?

quick sort is a divide and conquer method , it is not dynamic programming


What is c and c in computer programming?

C and C++ are both high-level programming languages.


Who invented the bubble sort?

ramesh


When would you use bubble sort?

Never. Bubble sort is often cited as an example of how not to write a sorting algorithm and is used purely as a programming exercise. It is never used in production code. Although reasonably efficient when sorting small lists, an insertion sort performs better on average. But for larger lists it has no practical uses. A merge sort is better for large lists, but if stability isn't an issue a quick sort is even better. Hybrid sorts typically use quick sort until a partition is small enough for an insertion sort to complete the job.


Sort a book list in a library based on the discipline USING C plus plus programming?

Write your own C++ functions for the following problems:o Sort a book list in a library based on the disciplineo Print the sorted output on the console


Create a spiral in C programming?

create spiral in c programming?


Bubble sort Extra or in space?

Bubble sort is an "in place" algorithm. Other than a temporary "switch" variable, no extra space is required.


What has the author Robert Lafore written?

Robert Lafore has written: 'Object-oriented programming in Microsoft C++' -- subject(s): Object-oriented programming (Computer science), C++ (Computer program language), C. 'Microsoft C. Programming for the I.B.M.Personal Computer' 'Object-oriented programming in C++' 'Windows Programming Made Ridiculously Easy Book' 'The Waite Group's C Programming Using Turbo C++ (The Waite Group)' 'Microsoft C programming for the IBM' 'The Waite Group's Microsoft C programming for the PC' -- subject(s): C (Computer program language), IBM microcomputers, Microsoft C (Computer program), Microsoft C., Programming