No errors... error...

I'm attempting to make a list of random numbers and then sort it into a least to greatest order. I used bubble sort as my algorithm for sorting them, but somewhere the program is either freezing, the output is failing, or a loop is infinite because it never outputs anything or gives me a runtime error message. I can't figure it out. It compiles with no errors or warnings in MS vc++ 6.0 Enterprise


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
void LTG_bubble_sort(int size);
int x, y, z, a, b, c;
int numbers[200];

void main()
{

	cout << "hi.";

    srand(time(NULL));

	x=0;

	do
	{
		numbers[x]=rand() % 1000+1;

		y=0;

		do
		{

			if(numbers[x]==numbers[y])
			{x--; break;}

			y++;
			cout << numbers[x];

		}while(y<x);

		x++;
	}while(x<200);


	//Least to greatest

	LTG_bubble_sort(x);

	//Cout

	y=0;
	a=0;

	do
	{
		y=0;

		do
		{
				cout << numbers[y] << "   ";
				y++;
		}while(y<10);

		a++;
		cout << '\t';
	}while(a<x);
}


void LTG_bubble_sort(int size)
{

	int swap_one;
	int swap_two;
	int swapped;

	do
	{
		swapped=0;

		for(int increment=0; increment<size-1; increment++)
		{
			if(numbers[increment]>numbers[increment+1])
			{
				swap_one=numbers[increment];
				swap_two=numbers[increment+1];

				numbers[increment]=swap_two;
				numbers[increment+1]=swap_one;

				swapped=1;
			}
		}

	}while(swapped!=0);

}
Last edited on
Topic archived. No new replies allowed.