### Arrays and Pointers assistance, please?

Pages: 12
Right, I'm nearly there. Just give me a few more mins and I'll show you my changes and such :)
tysm, im still trying to fix visual studio X_X. getting my other friend to run the program for me just to see if it works, cuz apparently his visual studio works but not mine =_____=
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576`` ``````#include #include using namespace std; void display(char* A[], int size){ for (int i = 0; i <5; i++) { cout << A[i] << endl; } } void swap(char* A[], int i, int j){ char* tmp = A[i]; A[i] = A[j]; A[j] = tmp; } int partition(char* A[], int low, int high){ int i = low; int j = high; int mid = (low + high) / 2; char* pivot = A[mid]; swap(A, low, mid); //swaps the pivot into A[low] while(i <= j) { //skip over elements <= the pivot while (i <= high && A[i] <= pivot) { i++; } //skip over elements > the pivot while(low <= j && pivot < A[j]) { j--; } //swap values at i & j if (i < j) swap(A, i, j); } swap(A, low, j); return j; } void QuickSort(char* A[], int low, int high){ if(low < high) // recursive case { int mid = partition(A, low, high); QuickSort(A, low, mid-1); QuickSort(A, mid+1, high); } } int main() { int SIZE; string wordToSort; cin >> wordToSort; SIZE = wordToSort.length(); char *suffixes[SIZE]; for(int index = 0; index < SIZE; index++) { suffixes[index] = &wordToSort[index]; } QuickSort(suffixes, 0, SIZE); display(suffixes, SIZE); }``````

This is what I have done and everything works properly except for your QuickSort wrong which is wrong. Now The code here I have given you will compile and all the function parameter are correct for all the functions. I'll keep mulling over the QuickSort, but I can see problem one which is when you try recursion on the function you call the function twice which cannot happen because it calls function one and the second one is ignored. So you need to try and fix your QuickSort function and as far as I'm aware everything else works. I'll keep looking over QuickSort too and post if I find any good changes.
Topic archived. No new replies allowed.
Pages: 12