15,029,958 members
See more:
what is the code of bubble sorting?
Posted
Updated 19-May-20 6:23am
[no name] 24-Aug-13 11:07am

Well that would be the code that you have written that performs a bubble sort.
Syeda Fatimah 24-Aug-13 11:14am

[no name] 24-Aug-13 11:24am

What about its code? There is not a single line of code in your blatant request for someone to do your research for you.

## Solution 1

'Bubble sort' is an algorithm for sorting data. You may find (many) details in the dedicated Wikipedia page[^].
It is easy to implement but very inefficient.
The 'code of bubble sorting' is the code you have to write, in your favourite programming language, in order to transform such an algorithm in an application (or a library function). Since the linked Wikipedia's page provides pseudo-code, your task is really easy.
Syeda Fatimah 24-Aug-13 11:17am

Thanx alotttt
CPallini 24-Aug-13 11:52am

You are welcome.
Syeda Fatimah 25-Aug-13 2:23am

:)

## Solution 2

A Google Search with keywords bubble sort source code returns links to several web sites that show the Bubble Sort source code. Below are just three of them.

Note that a Bubble Sort performs less than optimally. A better sort algorithm is Shell Sort. Many years ago, I did some testing and found that for any more than 12 items, bubble sort performed worse than Shell Sort. It may be different today but bubble sort would not be my choice for a sort algorithm.

C program for bubble sort [^]

Java program to bubble sort[^]

Wikipedia article: Bubble Sort including source code[^]
CPallini 24-Aug-13 11:52am

"It may be different today"
Why?
Mike Meinz 24-Aug-13 13:31pm

I don't know if it is different or not because I have not tested it. I am sure, though, that in most cases Shell Sort is better than Bubble Sort.
CPallini 24-Aug-13 13:37pm

If you perform the same test then you get the same results.
By the way, on relatively large data, the shell sort is superior to the bubble sort (actually the bubble sort is the worst sorting algorithm) there is a lot of literature about, see, for instance, the oldie-goldie Wirth's "Algorithms + data structures = programs".

## Solution 4

```#include<stdio.h>

int main()
{
int n, i, j, a[5], b, temp;
printf("Enter the number of elements to be sorted\n");
scanf("%d", &n);
for(i = 0; i < n; ++i)
{
printf("%d - Enter the elements - ", i);
scanf("%d", &a[i]);
}
for(i = 0; i < n; i++)
{
for(j = 0; j < n-1; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
for (i = 0; i < n; ++i)
{
printf("%d\n", a[i]);
}
return 0;
}```