hello good people
I am doing indexsort of name and surename.
i have some error with index in my sort2 fuction.
I can not figure outwhat is wrong.
can somebody give me a hint about what to do to fix it.
I was also wondering if I can add a list of cities as well.
thanking you in advance.
#include <iostream>
#include <string>
using namespace std;
void prompt(string name[7], string surename[7]);
void init(int index[7]);
void sort(string name[7], int index[7]);
void sort2(string surename[7], int[7]);
void output(string surename[7], string name[7], int index[7]);
int main()
{
string name[7];
string surename[7];
int index[7];
prompt(name, surename);
init(index);
sort(name, index);
sort(surename,index);
output(surename, name, index);
}
void prompt(string name[7], string surename[7])
{
for(int i=0;i<=6;i++)
{
cout << "Please enter name: ";
cin >> name[i];
cout << "Please enter surename: ";
cin >> surename[i];
}
}
void init(int index[7])
{
for(int i=0;i<=6;i++)
{
index[i]=i;
}
}
void sort(string name[7], int index[7])
{
int i, j;
for(i=0;i<=5;i++)
{
for(j=i+1;j<=6;j++)
{
int temp;
if(name[index[i]] > name[index[j]])
{
temp = index[i];
index[i] = index[j];
index[j] = temp;
}
}
}
}
void sort2(string surename[7], int[7])
{
int d, t;
for(d=0;d<=5;d++)
{
for(t=d+1;t<=6;d++)
{
int temp;
if(surename[index[d]] > surename[index[t]])
{
temp = index[d];
index[d] = index[t];
index[t] = temp;
}
}
}
}
void output(string surename[7], string name[7], int index[7])
{
int i;
cout << endl;
for(i=0;i<=6;i++)
{
cout << surename[index[i]] << " "
<< name[index[i]] << endl;
}
cin.ignore();
cin.get();
//system("pause");
}