y u no do it?

Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

Starts at just \$1 per CPM or \$0.10 per CPC.

# Bubble Sorting

Discussion in 'Databases' started by honeyclarck, Apr 13, 2012.

1. #1
I know what is the meaning of sort. But recently i hear the Bubble sort. So tell me please what is Bubble Sort?

Apr 13, 2012 IP
2. ### plogPeon

Messages:
298
11
1
Trophy Points:
0
#2
, Apr 13, 2012 IP
3. ### mikewellerPeon

Messages:
14
0
3
Trophy Points:
0
#3

But generally, you don't need to know how the sorting is done. Just use "order by" in your SQL and the database will do the sorting for you.

Apr 14, 2012 IP
4. ### Decode141Peon

Messages:
1
0
0
Trophy Points:
0
#4
So, basically if you want to sort 4,3,2,1 using bubble sort, you'd do:
Compare 4 with 3, if 4 is larger we swap. We repeat this till 4 is compared with every other element. So...
3|4|2|1 Swapped 3 and 4
3|2|4|1 Swapped 2 and 4
3|2|1|4 Swapped 1 and 4

Now we do the same for 3.
2|3|1|4 Swap 2 and 3
2|1|3|4 Swap 3 and 1
2|1|3|4 Since 3 is not greater than 4, we don't swap.

Lastly we do this for 2.
After this we get 1|2|3|4

It's rather slow and most databases use better sorting algorithms like Quick Sort or Merge Sort.

Apr 15, 2012 IP
5. ### honeyclarckPeon

Messages:
196
1
0
Trophy Points:
0
#5
Thanks a lot to telling can you know the site or tell me more about Bubble sort where can i read it.

Apr 19, 2012 IP
6. ### rok86Greenhorn

Messages:
7
0
0
Trophy Points:
11
#6
Bubble sort is also a type of algorithm which is use to sort the given set of number .

Apr 19, 2012 IP
7. ### javamazonActive Member

Messages:
50
0
0
Trophy Points:
66
#7
Bubble Sorting is an algorithm in which we are comparing first two values and put the larger one at higher index. Then we take next two values compare these values and place larger value at higher index. This process do iteratively until the largest value is not reached at last index. Then start again from zero index up to n-1 index. The algorithm follows the same steps iteratively unlit elements are not sorted.

In Term of java this is simple program :

public class bubbleSort{
public static void main(String a[]){
int i;
int array[] = {12,9,4,99,120,1,3,10};
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print( array+" ");
System.out.println();
bubble_srt(array, array.length);
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array+" ");
System.out.println();
System.out.println("PAUSE");
}

public static void bubble_srt( int a[], int n ){
int i, j,t=0;
for(i = 0; i < n; i++){
for(j = 1; j < (n-i); j++){
if(a[j-1] > a[j]){
t = a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
}

Apr 20, 2012 IP