Reputation: 1142
I'm trying to sort an array of pointers to words lexicographically and the sort itself seems to work, except of the swap, i tried many formats and i can't make it work, hope you could help me:
for(i=1;i<words;i++){
for(j=i;j>0 && strcmp(dicArray[0][j-1],dicArray[0][j]) == 1;j--){
temp = dicArray[0][j];
dicArray[0][j-1] = dicArray[0][j];
dicArray[0][j] = temp;
}
}
Upvotes: 0
Views: 113
Reputation: 2738
Your swapping algo is not correct.
If you want to swap dicArray[0][j-1]
and dicArray[0][j]
, then do the following:
temp = dicArray[0][j];
dicArray[0][j] = dicArray[0][j-1];
dicArray[0][j-1] = temp;
Upvotes: 11