I'm currently doing a quick sort on a multidimensional array with a bunch of words in it. When it prints out, it's just completely out of order and I thought I was sure that what I did was correct. Do you see any errors that I could've made??
Code:void quickSort(char newList[][20], int low, int high){ //passed it correctly //these are indexes only int i = low; int j = high; int mid = ((low+high)/2); char pivot[20]; strcpy(pivot, newList[mid]); char temp[20]; //partition while(i<=j){ // while (i<=j) while(strcmp(newList[i], pivot) == -1){ //while (i<pivot) i++; } while(strcmp(newList[j], pivot) == 1){ //while (j>pivot) j--; } //SWAP if(i<=j){ strcpy(temp, newList[i]); strcpy(newList[i], newList[j]); strcpy(newList[j], temp); i++; j--; } } //recursion if(strcmp(newList[low],newList[j]) == -1){ quickSort(newList, low, j); } if(strcmp(newList[i],newList[high]) == -1){ quickSort(newList, i, high); } }



1Likes
LinkBack URL
About LinkBacks



The one thing I'd like to see is if I could sort a list of words with different cases and numbers :X I'm gonna make a few changes to see if I can implement that!