Bubble sort of a text file problem. Help

Hi,
I need to do a simple bubble sort function for a file as my assignment. So far I've come up with this and I have no idea why it's doing what it's doing. He prints out one line from the file and then repeats another a million times. I hope you can understand the code even though it has Croatian names for variables.
Thanks in advance.


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
 #include<iostream>
#include<string>
#include<fstream>
using namespace std;

struct grad
{
	int posBroj;
	string nazivMjesta;
};




void bubble_sort(grad polje[], int velicina)
{
	grad tmp;

	for(int i=velicina-1;i>0;i--)
	{
		for(int j=0;j<i;j++)
		{
			if(polje[j].posBroj > polje[j+1].posBroj)
			{
				tmp = polje[j];
				polje[j+1]=polje[j];
				polje[j+1]=tmp;
			}
		
		}
	}
}

int main(){
	grad polje[200];
	fstream ulaz;
	ulaz.open("pb_unsorted.txt");
	int i=0;

	while(ulaz >> polje[i].posBroj)
	{
		ulaz >> polje[i].nazivMjesta;
		i++;
	}

	bubble_sort(polje, i);
	for(int j=0; j<i; j++){
		cout << polje[j].posBroj << " " <<polje[j].nazivMjesta <<endl;
	}


	system("pause");
	return 0;
}
Topic archived. No new replies allowed.