C, C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
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
38 9 7 1
3 89 7 1
3 8 79 1
3 8 7 19
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.
38 7 1 9
3 78 1 9
3 7 18 9
37 1 8 9
3 17 8 9 Fourth Passage
13 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;
Report Bad Submission
Other User Comments
There are no comments on this submission.
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)
My nonprogramming sites: The Real Estate Crowdfunding Review: Investing tools that cut through the clutter and the hype.
Real information and reviews. Real-time investment feeds. Real profitable. | Dollar candy: Play 60 second puzzles against three other people for real money! Legal in 36 states and overseas.