bubble sort problem

Hi Guys

I Have created a program, where the user will choose how many numbers they would like to the computer to generate. Once this happens then bubble sort is applied. I have a problem. Now bubble sort works, but repeating numbers are removed.Also if i say to the program that i want to generate numbers less than 10, for some reason i get loads of 000000 in my buble sort. Here is the code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void bubble()
{
	int l1, l2, tempitem;
	for(l1=9; l1>0; l1--)
	{
		for(l2=0; l2<l1; l2++)
		{
			if(number[l2]>number[l2+1])
			{
				tempitem = number[l2+1];
				number[l2+1] = number[l2];
				number[l2] = tempitem;
			}
		}
	}
	cout<<"Your Sorted Numbers, using Bubble sort are: \n";
	for(l1=0;l1<10;l1++) cout << number[l1] <<", ";
	cin.get();

}


Thanks for any help

Michael
And thats why variable names that start with a number are not allowed.

The loop isn't correct, but you've got to change those name first.
I think his variables are lower case "L" 1 and lower case "L" 2. But it definitely makes the code confusing.
Ok, so if I change my variable names to something less confusing, what could be the problem?
That's not a bubble sort. You may want to reacquaint yourself with the algorithm.

http://en.wikipedia.org/wiki/Bubble_sort
closed account (18hRX9L8)
You are not defining type number[].
Last edited on
Topic archived. No new replies allowed.