Click here to Skip to main content
15,029,958 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
what is the code of bubble sorting?
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
i've not written its code.and askin' about its code
[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.

'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
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"
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".

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;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900