hi! i'm having a hard time in understanding the "bubble sort", can anybody please help me in creating a programming that allows the user to input 10 integers and gives them an option whether it will display from "hi to low" or "low to hi". thanks in advance.

6 Years
Discussion Span
Last Post by dcasmac418

//Assumptions :
//1)Data to be sorted is stored in an array
//2)Data to be sorted is of integer type
//3)Sorting is done in Ascending order.
Simple Logic :

int array[10]; //array of size 10 
int store;
for(int i = 0; i < array.length(); i++)
    for(j = i+1; j < array.length(); j++)
         if (array[i] > array[j])
             tmp = array[i];
             array[i] = array[j];  //swapping
             array[j] = tmp;

//after this loop the array will have it's data sorted in ascending order.
As for options you can always use a while loop to make a 'Menu driven' program :)
Hope this helps :)


Edited by KKR_WE_RULE: n/a

Votes + Comments
Wow, another giveaway program! Ain't we just a wonderful code shop here!

here is the algo......

procedure bubbleSort( A : list of sortable items )
swapped = false
for each i in 1 to length(A) - 1 inclusive do:
if A[i-1] > A then
swap( A[i-1], A )
swapped = true
end if
end for
while swapped
end procedure


thanks a lot, just what i needed, a guide to write my program. this will help a loooot. :D

will get back you for my code. do you mind double checking it later for any error?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.