dimanche 1 février 2015

Sorting a char**


Vote count:

0




so I'm creating an indexer for a project and we have to use a char** to store the words from a file. I'm trying to sort the words inside the array. Heres what I've tried so far:



void Word::arrangeWords(char **&words)
{

char **temp=new char*[getSize()];

temp[getSize()-1]=words[getSize()-1];
for (int i=getSize()-1;i>0;i--)
{
comp=strcmp(temp[i], temp[i-1]);
if (comp<0)
{
temp[i]=words[i-1];
temp[i-1]=words[i];
}
else
{
temp[i]=words[i];
}
}
delete [] words;
words=temp;
}


this ends up not working and I kind of understand why. Is the an easier way to sort it? Thanks in advance



asked 1 min ago







Sorting a char**

Aucun commentaire:

Enregistrer un commentaire