Hi I think there is a problem in your implementation.
Try {12,9,30,99,30,1,30,10,13};
The point is if there are more than one occurrences of the pivot and they are in symmetric positions then there is a problem.
Please point out if I'm wrong. Thanks
Jing
Hi,
Fantastic short and easy to remember algorithm but it does not allow duplicate entires. For example, in your code you use the data:
{12,9,4,99,120,1,3,10,13};
However, {12,9,4,99,120,1,3,10,13,13}; fails due to the extra 13.
Any chance you could update the algorithm?
David
hays gays i want to learn more about more details about QUICK SORT because this my project in are school just for give me because this my for my future thank you..
please help me in getting the output in this fashion. using array the below example is using link list though. but i need it in arrays.
please modify the above program so that i can get the following output.
Initial List: 5 -> 9 -> 2 -> 9 -> 7 -> null
Level 0: Before Left: 2 -> null
Level 0: Before Pivot is: 5
Level 0: Before Right: 9 -> 9 -> 7 -> null
Level 1: Before Left: 7 -> null
Level 1: Before Pivot is: 9
Level 1: Before Right: 9 -> null Level 1: After Left: 7 -> null Level 1: After Pivot is: 9
Level 1: After Right: 9 -> null
Level 0: After Left: 2 -> null
Level 0: After Pivot is: 5
Level 0: After Right: 7 -> 9 -> 9 -> null
Sorted List: 2 -> 5 -> 7 -> 9 -> 9 -> null
please test with: array[] = {12,99,4,99,120,1,3,10,13};
loop loop and loop...
need to change:
while (lo<hi && array[hi] > mid) {
---->
while (lo<hi && array[hi] >= mid) {
I think this description of quick sort is very complicated. The algo is simple.
take pivot, put all smaller items in left and bigger items in right. repeat same thru recursion...
I was using your method, but I found an exception, the programm hangs out when we have for example an array: 12,9,4,99,12,1,3,10,13 where there are two number 12. I'd would like to know why it's happening when we execute that? Thanks in advantage.
Kind Regards.
Try this array :
int array[] = {-12, 9, 4, 99, 120, -1, 3, 10, -1};
int array[] = {-12, 9, 4, 99, 120, -1, 3, 10, -12};
recursion does not finish with negative numbers in some cases and even with positive numbers like this :
int array[] = {120, 9, 4, 99, 120, 1, 3, 10, 120};
//does not finish
Fix it.
thank'sEuan April 11, 2011 at 11:43 PM
thank you
Bug?Jing May 25, 2011 at 12:26 AM
Hi I think there is a problem in your implementation. Try {12,9,30,99,30,1,30,10,13}; The point is if there are more than one occurrences of the pivot and they are in symmetric positions then there is a problem. Please point out if I'm wrong. Thanks Jing
computer sciencewishma prasad June 23, 2011 at 8:13 AM
i like this
This is incorrectSebastian June 24, 2011 at 1:46 AM
This is an incorrect implementation of Quick Sort. The algorithm fails for inputs such as this: 68 13 56 44 82 78 59 78 61 82
No duplicatesDavid September 22, 2011 at 7:22 PM
Hi, Fantastic short and easy to remember algorithm but it does not allow duplicate entires. For example, in your code you use the data: {12,9,4,99,120,1,3,10,13}; However, {12,9,4,99,120,1,3,10,13,13}; fails due to the extra 13. Any chance you could update the algorithm? David
quicksortjoseph October 13, 2011 at 9:52 AM
hays gays i want to learn more about more details about QUICK SORT because this my project in are school just for give me because this my for my future thank you..
Unable to run codeKaushalendra January 2, 2012 at 5:13 PM
kindly try to run this code for { 1, 3, 6, 4, 1, 8, 3, 9, 2, 0, 1 } I am not able to run it . It goes in an infinite loop
DudaMartin Hernandez Gonzalez January 13, 2012 at 10:32 AM
What happen if two numbers be repeated? thanks for your explication...
Incorrect implementationVivek January 17, 2012 at 11:47 PM
The implementation is incorrect. It fails for input 1,2,3,4,8,9,76,54,58,50,322,11,44,11
changing the output of the quick sort.riz January 24, 2012 at 6:20 AM
please help me in getting the output in this fashion. using array the below example is using link list though. but i need it in arrays. please modify the above program so that i can get the following output. Initial List: 5 -> 9 -> 2 -> 9 -> 7 -> null Level 0: Before Left: 2 -> null Level 0: Before Pivot is: 5 Level 0: Before Right: 9 -> 9 -> 7 -> null Level 1: Before Left: 7 -> null Level 1: Before Pivot is: 9 Level 1: Before Right: 9 -> null Level 1: After Left: 7 -> null Level 1: After Pivot is: 9 Level 1: After Right: 9 -> null Level 0: After Left: 2 -> null Level 0: After Pivot is: 5 Level 0: After Right: 7 -> 9 -> 9 -> null Sorted List: 2 -> 5 -> 7 -> 9 -> 9 -> null
algorithms and datastructuresm.nadipi naganna March 15, 2012 at 5:34 PM
u r services is very excellent.
codeC: May 7, 2012 at 11:39 AM
helped alot thanks
more than 2 numbers are equal!!Nguyen Chi Vien June 2, 2012 at 12:17 AM
please test with: array[] = {12,99,4,99,120,1,3,10,13}; loop loop and loop... need to change: while (lo<hi && array[hi] > mid) { ----> while (lo<hi && array[hi] >= mid) {
algo review..Raj June 8, 2012 at 5:01 PM
I think this description of quick sort is very complicated. The algo is simple. take pivot, put all smaller items in left and bigger items in right. repeat same thru recursion...
try this code for....{11,12,12,1}varun June 30, 2012 at 12:17 AM
try this code for....{11,12,12,1}..there is some issue....loop is not breaking....
This is a bad implementation of quick sort!Matt July 1, 2012 at 5:55 AM
Use {0,0,0} as the input and it will loop forever! Shame on you.
solution doesnt workAmit July 10, 2012 at 10:23 PM
Hangs for the input 9 7 7 2 2 3
where is 9 on the result?korea July 30, 2012 at 11:33 AM
title
There is some problem in the above codeArumugam August 8, 2012 at 10:15 AM
try this Array int array[] = { 1,2, 8, 2, 6, 0, 11, 13, 3, 4 };
this code fails for duplicate valuesAfsar Ali August 31, 2012 at 8:52 PM
this code fails for duplicate values
ExceptionIvan Garcia October 9, 2012 at 9:08 PM
I was using your method, but I found an exception, the programm hangs out when we have for example an array: 12,9,4,99,12,1,3,10,13 where there are two number 12. I'd would like to know why it's happening when we execute that? Thanks in advantage. Kind Regards.
Not working fineRaul November 11, 2012 at 8:22 AM
Try this array : int array[] = {-12, 9, 4, 99, 120, -1, 3, 10, -1}; int array[] = {-12, 9, 4, 99, 120, -1, 3, 10, -12}; recursion does not finish with negative numbers in some cases and even with positive numbers like this : int array[] = {120, 9, 4, 99, 120, 1, 3, 10, 120}; //does not finish Fix it.
Not as explainedANdres Luque March 26, 2013 at 11:06 AM
Hello, if you print each step of the quicksort method you will see that the steps of finding the high value and swaping are wrong
ExplanationMario April 14, 2013 at 7:33 PM
Please can you explain me: quick_srt(array, low, lo); quick_srt(array, lo == low ? lo+1 : lo, n); Thanks in advance.
Post your Comment