Sorting two arrays?

I'm stumped in regards to sorting two different types of arrays. My goal is to output from the below code:

Bob
Bob 0
Joe 40
Sue 100

Joe
Joe 0
Bob 40
Sue 60

Sue
Sue 0
Joe 60
Bob 100

Essentially, I need the outer for loop to be alphabetically sorted (hence the alphasort function) and the inner for loop to sort the values in an increasing order as well as display the names of the differences performed. I can't seem to figure out how to accomplish my goal.

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
  #include <iostream>
#include <string>
#include <cmath>

using namespace std;

void alphasort(string a[]);
void weightsort(int weight[]);

int main () {
	string a[3] = {"Bob", "Sue", "Joe"};
	int weight[3] = {220, 120, 180}; 

	alphasort(a); 

	for (int i = 0; i < 3; i++) {
		cout << a[i] << endl;
		for (int j = 0; j < 3; j++) {
			weightsort(weight); 
			cout << a[j] << "\t" << sqrt(pow(weight[i] - weight[j], 2) << endl;
		}
		cout << endl;
	}


	return 0;
}

void alphasort(string a[]) {
	string temp;
	for (int i = 1; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (a[j] > a[i]) { 
                temp = a[j];
                a[j] = a[i];
                a[i] = temp; 
            }
        }
    }
}

void weightsort(int weight[]) {
	int temp;
	for (int i = 1; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (weight[i] < weight[i - 1]) {
                temp = weight[i];
                weight[i] = weight[i - 1];
                weight[i - 1] = temp;  
            }
        } 
    }
}
The point is that you need to pass both arrays to alphasort(...) and weightsort(...). And you need to perform the swap operation to both arrays.
Topic archived. No new replies allowed.