# Bubble Sorting

This is a discussion on Bubble Sorting within the C++ Programming forums, part of the General Programming Boards category; Can Somebody Explain this to me??? Code: #include <iostream> #include <iomanip> using namespace std; int main() { const int NUM_QUIZZES ...

1. ## Bubble Sorting

Can Somebody Explain this to me???
Code:
```#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int NUM_QUIZZES = 3;

int quiz,            // Subscript for the array grade[]
temp,            // For swapping array elements
pass,            // The number of the pass
limit;           // Keeps track of how far to go on a pass

cout << "Please enter " << NUM_QUIZZES
<< " integer quiz grades." << endl << endl;

for (quiz = 0; quiz < NUM_QUIZZES; ++quiz)
{
cout << endl;
cout << "Enter grade for quiz " << quiz + 1 << ": ";
}

cout << endl << endl;
cout << "The grades you entered are as follows:" << endl;

for (quiz = 0; quiz < NUM_QUIZZES; ++quiz)

cout << endl;

// Do the bubble sort

limit = NUM_QUIZZES - 2;

for (pass = 1; pass <= NUM_QUIZZES - 1; ++pass)
{
cout<<"Pass: "<<pass<<endl;//1//2
for (quiz = 0; quiz <= limit; ++quiz)
{
}
limit;

}
// Display the sorted quiz grades

cout << endl << endl;
cout << "The grades in increasing order are as follows:" << endl;
for (quiz = 0; quiz < NUM_QUIZZES; ++quiz)

cout << endl;

return 0;
}```

why "num-quizzes minus 2", and why the "limit;" and why the "num quiz -1", under the do bubble sort comment????

2. it works perfectly , but i dont quiet understand how it works the bubble sorting..

3. Originally Posted by yukapuka
it works perfectly , but i dont quiet understand how it works the bubble sorting..
So run through the algorithm with some numbers and see how it works.

4. i am not very familiar with what u mean by running algorithm with some numbers ???
bear in mind your talking to a beginner so please elaborate with an example or something

thanks

5. Originally Posted by yukapuka
i am not very familiar with what u mean by running algorithm with some numbers ???
bear in mind your talking to a beginner so please elaborate with an example or something

thanks
Pick some numbers, and pretend you are the machine, and do all the steps and see what happens.

6. Thanks For The Advice , Problem Is Cleared...

7. The sort algorithm is doing a lot more comparisons than it's supposed to because of a bug with this line:
Code:
`     limit;`
It should be:
Code:
`     --limit;`

8. i sensed something wasnt adding up in order, even tho the program calculated correctly,
that does make a big diff thanks IMALC !!!