| | |
Quicksort problems
![]() |
•
•
Join Date: Sep 2006
Posts: 12
Reputation:
Solved Threads: 0
Hi there everyone. I wonder if you could help me with my code. It just seems to go into an infinite loop. I would greatly appreciate some help with this. Thanks
Thanks once again
C++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int qsrt(int array[], int first, int last) { int over = 0; over = first-last; int g=0; if(over==0) { return 0; } int c=0; int start = first; int end = last; int pivot = array[first]; int temp =0; while(first != last) { while((array[last]>pivot)&&(first != last)) { last--; } while((array[first]<pivot)&&(first != last)) { first++; } temp = array[last]; array[last] = array[first]; array[first] = temp; c = last-first; if(c>1) { first++; last--; } } c= 0; c= first-1; qsrt(array,first,end); qsrt(array,start,(c)); return 0; } int main (void) { int anarray[9] = {4,5,3,8,5,6,2,8,9}; qsrt(anarray,0,8); system("pause"); return 0; }
Thanks once again
c Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int qsrt(int array[], int first, int last){ int over = 0; over = first-last; int g=0; if(over==0){ return 0; }int c=0; int start = first; int end = last; int pivot = array[first]; int temp =0; while(first != last){ while((array[last]>pivot)&&(first != last)){ last--; }while((array[first]<pivot)&&(first != last)){ first++; }temp = array[last]; array[last] = array[first]; array[first] = temp; c = last-first; if(c>1){ first++; last--; } }c= 0; c= first-1; qsrt(array,first,end); qsrt(array,start,(c)); return 0; } int main (void){ int anarray[9] = {4,5,3,8,5,6,2,8,9}; qsrt(anarray,0,8); system("pause"); return 0; }
first, you should learn how to format your code correctly...
second, saying this
C++ Syntax (Toggle Plain Text)
int a=0; a=b-c;
C++ Syntax (Toggle Plain Text)
int a=b-c;
third, what are you doing there? it seems like you are ordering numbers from least to greatest... but... JRM is right... you could do this with less variables...
Last edited by happygeek; Jun 11th, 2007 at 5:40 am. Reason: swears removed, keep it clean
-->sometimes i wanna take my toaster in a bath<-- ![]() |
Similar Threads
- Finally Almost Finished 2 Problems!! :( (C)
- Please help with my quicksort (C)
- Quicksort/Insertion sort Hyrbid? (C)
- No time... bitch load of problems (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Return Array from C++
- Next Thread: Using a switch statement with nested if/else statements
| Thread Tools | Search this Thread |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error faq file forms fstream function functions game givemetehcodez graph gui hash homeworkhelp homeworkhelper iamthwee ifpug ifstream infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets






