I want to sort and array of instances of a struct via qsort, but I'm really helpless yet... :-/ For two days I was trying to follow some tutorials, nevertheless I wasn't successful
I would really appritiate, if someone would be so nice and would look at my code and show me, how it shall be coded to work... I want simply sort the personArr by the property name.
PS:I can use only those includes
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
using namespace std;
class CPhoneBook
{
public:
struct item
{
string name;
string address;
string phone;
} ITEM;
int k;
item* personArr;
CPhoneBook (void);
~CPhoneBook (void);
bool Add ( const string & name, const string & address, const string & phone )
{
item i ;
i.name=name;
i.address=address;
i.phone=phone;
personArr[k++]=i;
sort();
return true;
};
void sort()
{
//here I want to sort personArr
}
bool Del ( const string & name, const string & address )
{
return true;
};
bool Search ( const string & name, const string & address, string & phone ) const
{
return true;
};
};
CPhoneBook::CPhoneBook ()
{
personArr = new item[1000];
k=0;
}
CPhoneBook::~CPhoneBook ()
{
delete []personArr;
}
int main ()
{
CPhoneBook rect;
rect.Add("a1","z2","z3");
rect.Add("x1","z2","z3");
rect.Add("0y","2","3");
rect.Add("z1","z2","z3");
}
The faster, the better....the deadline is close...thanks for any help..

New Topic/Question
Reply




MultiQuote






|