Bubble Sort Algo

Email
 Submitted on: 1/4/2015 5:07:00 AM By: d1rtyw0rm (from psc cd) Level: Beginner User Rating: By 4 Users Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++ Views: 877

It is a simple algorithm about howto sort an array of a number in chronological order

 ``` The sorting by bubble consists in traversing an array and to interchange each couple of numbers of which first ranks above the second. Several passages on the table will be necessary (exactly items_numbers - 1) Little exemple : ORIGINAL ARRAY : 8 3 9 7 1 First Passage 3 8 9 7 1 3 8 9 7 1 3 8 7 9 1 3 8 7 1 9 As of the first passage, the highest number is automatically thorough with the last position. Therefore, we will not need more to check it with other numbers at the time of the next passages. In the code which will follow, variable N discharges this task. In fact, each following passage will contain each one a checking of less than preceding it. Second Passages 3 8 7 1 9 3 7 8 1 9 3 7 1 8 9 Third Passages 3 7 1 8 9 3 1 7 8 9 Fourth Passage 1 3 7 8 9 The following algorithm sort each element of an array using the bubble sorting. The variables N and K are counter and swap is a variable being used like a temporarily contain to store a value at the time while interchangement as values between two variables. int n, k, swap; for (n = num - 1; n > 0; n--) { for (k = 0; k < n; k ++) { if (tab[k] > tab[k + 1]) { swap = tab[k]; tab[k] = tab[k + 1]; tab[k + 1] = swap; } } } -d1rtw0rm```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)