Hello, sorry to open same question on this forum but, I have no choice since I'm trying to implement nonrecursive quicksort using C++ STL.
i'm trying to correct code earlier posted on the board,
Quicksort
but I have problem with an infinite loop:
Please can you look this and correct it, I don't know what is wrong.Code:#include <stack> /*...*/ void quicksort_it(int *dataset,int dataset_size) { stack<int> st; int i,j,first,last,pivot; for(i=0;i<dataset_size;i++) st.push(dataset[i]); first= 0; last = dataset_size-1; while(!(st.empty())) { for(i=first;i<=last;i++) { dataset[i] = st.top(); st.pop(); } while(first<last) { // Split pivot = dataset[first]; i = first, j= last -1 ; for(;;) { while(dataset[i] <= pivot && i <= last) {i++;} while(pivot < dataset[j] && j >= first){j--;} if(i<j) swap(dataset[i],dataset[j]); else break; } swap(dataset[i],dataset[last-1]); for(i=pivot+1;i<=last;i++) st.push(dataset[i]); pivot=last-1; } } }
Thanks



LinkBack URL
About LinkBacks


