0

Hello

Im trying to understand and explain how the quick sort code actually works, i unable to understand or xplain line 4 to 11.
Can ne of u xplain to me briefly what those lines actually do in the code algorithm....
Apreciate ne help.

do {
while(strcmp(array[i].Genre,x)<0 && i<right) i++;       //line 2
while(strcmp(array[j].Genre,x)>0 && j>left) j--;	        //line 3

if(i<=j) {				                    //line 4
	temp = array[i];		                   //line 5
	array[i] = array[j];		                  //line 6
	array[j] = temp;		                  //line 7
	i++; j--;			                 //line 8
			
		}
	}while(i<=j);		                  //line 9
			
if(left<j) quick_sort(array, left, j);		     //line 10
if(i<right)quick_sort(array, i, right);		     //line 11
	}
2
Contributors
1
Reply
2
Views
11 Years
Discussion Span
Last Post by perniciosus
1

Try reading up on quicksort in general... The loop (lines 2-9) make sure that all the low values are in one range and the high values in the other... The recursive calls (lines 10,11) then does the same for these fixed subsections, untill the trivial case of one or two elements..

Votes + Comments
Thanks
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.