struct print issue

Pages: 12
list is the struct and i have it in the parameter, i think i need to do pass by reference because i need the order changed for the main function but im not sure how to do that because there are errors presented in it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void teamSort(List * bub, int length)
{
	List temp;
	for (int i = 1; i < length; i++)
	{
		for (int j = 0; j < length - i; j++)
			if (bub[j].diff() > bub[j + 1].diff())
			{
				temp = bub[j];
				bub[j] = bub[j + 1];
				bub[j + 1] = temp;
			}
	}
}

i have here the pass by reference function but for some reason when i try to enter 4 so it displays the order of the file, it never changes to be in the ascending order.
Last edited on
Yes, that looks rather better.

My attempt at the same function has
 
void teamSort(list bub[], int length)
instead of
 
void teamSort(List * bub, int length)

Both versions do the same thing, they pass a pointer to the first element of the array.

(note that passing by reference is something a little different to this).

when i try to enter 4 so it displays the order of the file, it never changes to be in the ascending order.

1. Make sure that you actually call the teamSort() function.
2. Currently the function sorts into descending, not ascending order. Change the comparison operator > to < in the sort function to get ascending order.
 
    if (bub[j].diff() < bub[j + 1].diff())

Topic archived. No new replies allowed.
Pages: 12