you can create a class ABC, which will hold 3 fields: int a, int b, char c.
implement the operator< for this class, and create a ABC[] of the approppriate size and populate it such that ABC[i] = ABC(a[i],b[i],c[i]).
implement the operator< so it will compare only a, and use sort on the ABC array.
after done sorting, you have all your elements in the desired order, just iterate the ABC array and populate the other arrays.
EDIT:
simplified [and hard coded] code sample:
#include <iostream>
#include <algorithm>
using namespace std;
class ABC {
public:
int a,b;
char c;
bool operator<(const ABC& other) const {
return a < other.a;
}
};
int main() {
int a[4] = {3,1,5,4};
int b[4] = {7,9,11,3};
char c[4] = {'A','B','C','D'};
ABC abc[4];
for (int i = 0; i< 4; i++) {
abc[i].a = a[i];
abc[i].b = b[i];
abc[i].c = c[i];
}
sort(abc,abc+4);
for (int i = 0; i < 4; i++) {
a[i] = abc[i].a;
b[i] = abc[i].b;
c[i] = abc[i].c;
}
cout << "a= [" << a[0] << ", " << a[1] << ", " << a[2] << ", " << a[3] << "]" << endl;
cout << "b= [" << b[0] << ", " << b[1] << ", " << b[2] << ", " << b[3] << "]" << endl;
cout << "c= [" << c[0] << ", " << c[1] << ", " << c[2] << ", " << c[3] << "]" << endl;
return 0;
}
works good for me on codepad: http://codepad.org/eCyNkyqR
x[1000]when just using 4 elements?'s:char c[1000] = {'A', 'B', 'C', 'D'}(unless they arecharvariables defined elsewhere)