Sort algorithm for Pancake Glutton

Hi all, I'm new here and was just doing the Pancake Glutton beginner exercise. Anyway, here's the code for my sorting algorithm (it's a bubble sort, I didn't want to copy anything that I didn't understand). It's supposed to rearrange the people in descending order along with the person number within the array itself (list[NUMBERPEOPLE][2]), so that I can simply do a for (x = 0; x<NUMBERPEOPLE; x++) loop after this in main() to output the ordered list.
Problem is, the list is not getting rearranged. The cout at the end just outputs a string of 10 sets of the data in list[0][x], while I expected it to change to reflect the rearrangement of the array.
So is there something wrong with my loops or is it a problem with my swap function?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void sortlist()
{
	bool done = false;
	while (!done)
		for (int x = 0; x < NUMBERPEOPLE /*I used a #define so I could edit the number easily for testing*/; x++)
		{
			if (list[x][1] > list[x+1][1])//compares two adjacent values, from the bottom
			{
				int temp[2];
				temp[0] = list[x][0];
				temp[1] = list[x][1];
				list [x][0] = list[x+1][0];
				list [x][1] = list[x+1][1];
				list[x+1][0] = temp[0];
				list[x+1][1] = temp[1];
				done = false;
			}
			else
			{
				done = true;
			}
			cout << list[0][0] << list[0][1];//testing to see if rearrangement has occurred
		}
}
Oh, I just read to the end of the thread on the beginner exercises page, feel like an idiot now. In that case, I guess my question would be, is there any way to achieve the same function without using classes/structs?
I all new to this as well and haven't fully gotten the hang of classes/structs yet, so I came up with this.

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

int inputarray[10][2];
int sortarray[10][2];

void outputarrays () {
    for (int v=0; v<10; v++) cout<<"Person "<<sortarray[v][1]<<" ate most pancakes - "<<sortarray[v][0]<<endl;
}

void shiftarrayright (int b) {
    for (int z=9; z>b; z--) {
        sortarray[z][0]=sortarray[z-1][0];
        sortarray[z][1]=sortarray[z-1][1];
    }
}

void comparevalues (int a) {
    for (int y=0; y<10; y++) {
        if (inputarray[a][0]>sortarray[y][0]) {
            shiftarrayright(y);
            sortarray[y][0]=inputarray[a][0];
            sortarray[y][1]=inputarray[a][1];
            break;
        }
    }
}

void shipvalue () {
    for (int x=0; x<10; x++) comparevalues(x);
}

int main ()
{
    for (int x=0; x<10; x++) {
        cout<<"Please input how many pancakes person "<<x+1<<" ate: ";
        cin>>inputarray[x][0];
        inputarray[x][1]=x+1;
    }
    shipvalue();
    outputarrays();
    cin.get();
    return 0;
}


It seems a lot more clumsy than yours though.
Topic archived. No new replies allowed.