Home Discussion Discuss: Quick Sort In Java

  • 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

  • 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

  • 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...

  • 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.

  • for those who faces problem with duplicate entrieswaheduzzaman June 16, 2013 at 7:03 PM

    just place an 'if' condition to check whether it has the same value or not. If there is a match just let it where it is..otherwise let it execute other condition.. The code should be like: public static void quick_sort(......){ ................. ........... .................... ............. if(array[hi]==array[lo]){ //here do nothing } if (lo < hi) { int T = array[lo]; array[lo] = array[hi]; array[hi] = T; } if (lo < hi) { int T = array[lo]; array[lo] = array[hi]; array[hi] = T; } } hope this will help... thanks

  • a suggestiomadil madih August 1, 2013 at 11:16 PM

    Hi, i really love this site, but noticing some of your ads deviating from serving your mission, which is contributing to research and accademia, makes me really wondering. i strongly suggest that you get ride of that offensive dating ad. those pictures dont inspire of dating, but of prostitution. come on guys looke at them. Regards, Adil

  • Bug Fixediano90 November 18, 2013 at 10:38 PM

    along with the help of a tutor in college we managed to solve the problem where reoccurring values would cause an infinite loop. This was due to a missing counters within the if statement at the end of a while loop. This was causing the loop while loop to freeze. The correct code should be: while (lo < hi) { while (lo<hi && array[lo] < mid) { lo++; } while (lo<hi && array[hi] > mid) { hi--; } if (lo < hi) { int T = array[lo]; array[lo] = array[hi]; array[hi] = T; lo++; hi--; } }

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
Java Beginners

Sort
with this A program is required to ask users to rate the Java programming language... Scanner(System.in); System.out.print("Rate Java(0-10): "); int rate..."); } } } } System.out.print("Invalid! Rate Java within the range(0-10): "); rate=input.nextInt 

Java Interview Questions

insertion sort
insertion sort  write a program in java using insertion sort 

Java Interview Questions

insertion sort
insertion sort  write a program in java using insertion sort 

Java Interview Questions

insertion sort
insertion sort  write a program in java using insertion sort 

Java Interview Questions

bubble sort
bubble sort  write a program in java using bubble sort 

Java Interview Questions

insertion sort
insertion sort  write a program in java using insertion sort 

Java Beginners

buble sort
buble sort  ascending order by using Bubble sort programm   Java BubbleSort Example 

Java Beginners

SEARCH AND SORT
SEARCH AND SORT  Cam any one provide me the code in java that : Program to search for MAX,MIN and then SORT the set using any of the Divide and conquer method 

Java Beginners

bubble sort - Java Beginners
bubble sort  how to write program The bubble-sort algorithm in double...  Hi friend, Bubble Sort program : public class...[] = {10,5,3,89,110,120,1,8,2,12}; System.out.println("Values Before the sort:\n 

Java Beginners

Java insertion sort question
Java insertion sort question  I've got another program that I need help with. I am trying to write a Java method that accepts an array of strings, and sorts the strings using the insertion sort algorithm. Then I need to write 

Java Beginners

sort java - Java Beginners
sort java  1. A statistics company wants to keep information of families. The information of a family is the family name, the number of members and first name of each member. The families are sorted alphabetically by family name 

Java Interview Questions

search and sort techniques in java
search and sort techniques in java  Hi i attened an interview recently... they asked to write all searching and sorting technique codes in java.. i... of all these searchings and sortings in java...please help... Regards, Anugnya 

Java Beginners

Insertion Sort - Java Beginners
Insertion Sort  Hello rose india java experts.If you don't mind.Can you help me.What is the code for Insertion Sort and Selection Sort that displays...: public class InsertionSort { public static void sort(String[] array) { int 

Java Beginners

Java Dictionary-Sort,Extract
Java Dictionary-Sort,Extract  *I need to make an English(other language) dictionary by collecting english/other language words in a text file;then using that text file I need to sort the words collected in alphabetical order 

JSP Servlet Questions

sort function - JSP-Servlet
sort function  How to sort a string variable in java   Hi friend, Please give in details and full source code to solve the problem. For information on java visit to : http://www.roseindia.net/java 

Java Beginners

Insertion Sort Timer
Insertion Sort Timer  Welcome all I wanna program in java find the timer of insertion sort and find time complexity for random value thanks all 

Java Beginners

array sort - Java Beginners
array sort  hi all, can anybody tell me how to sort an array without any in-built methods.   Hi Friend, Try the following code: public class SortArrayWithoutUsingMethod{ public static void sortArray(int 

Java Beginners

heap sort in java
heap sort in java  plz modify this program so that it can take input as integers and string both..... public class heap_Sort{ public static void...("\n Heap Sort\n---------------\n"); System.out.println("\n Unsorted Array\n\n 

General

Heap Sort in Java
Heap Sort in Java is used to sort integer values of an array. Like quicksort.... Example of Heap Sort in Java: public class eap_Sort{ public static void main...\sorting>Javac heap_Sort.java C:\array\sorting>java heap_Sort Heap Sort 

Java Tips and Examples

Merge Sort Java
Merge Sort in Java is used to sort integer values of an array. There are many methods to sort Java like bubble sort, insertion sort, selection sort, etc.... Example of Merge Sort in Java public class mergeSort{ public static void main 

Java Beginners

Help With Costructing Selection sort?
in advance!   Please visit the following link: Java Selection Sort...Help With Costructing Selection sort?  Using a selection sort, for each entry in the array, display the original index of the first dimension 

Java Tips and Examples

Quick Sort in Java
Quick sort in Java is used to sort integer values of an array... into a sorted array. Example of Quick Sort in Java: public class QuickSort... QuickSort.java C:\array\sorting>java QuickSort RoseIndia Quick Sort 

Java Tips and Examples

Insertion Sort In Java
Insertion Sort In Java     .... There are more efficient algorithms such as quick sort, heap sort, or merge sort... In this example we are going to sort integer values of an array using insertion sort 

Java Tips and Examples

Selection Sort In Java
Selection Sort In Java      ... are going to sort the values of an array  using selection sort.In selection sorting.... Sort the remaining  values by using same steps. Selection sort  

Java Tips and Examples

Merge Sort In Java
Merge Sort in Java      ... to sort integer values of an array using merge sort. In merge sorting.... Then merge both parts and sort it. Then again merge the next part and sort it. Do 

Java Tips and Examples

Quick Sort In Java
Quick Sort in Java      ...;java QuickSort RoseIndia Quick Sort... to sort integer values of an array using quick sort. Quick sort algorithm 

Java Beginners

Merge Sort String Array in Java
Merge Sort String Array in Java  Hello, I am trying to implement a merge sort algorithm that sorts an array of Strings. I have seen numerous.... Note: I have a separate class for merge sort in which i pass my list and the size 

Java Beginners

Sort the element find mean
Sort the element find mean  Hi Friend, I want to find meaning of some real numbers like, if we have numbers- 52.15, 89.0, 314.48, 845.75... developing this program in java..Please help me to solve this problem ASAP 

Java Beginners

Sort
Sort  program to sort a list of numbers in decendimg order   Hi Friend, Try the following code: import java.util.*; class SortListInDescendingOrder{ public static void main(String[] args 

Java Tips and Examples

Bidirectional Bubble Sort in Java
Bidirectional Bubble Sort in Java       Introduction : Bidirectional Bubble Sort In this example we are going to sort integer values 

DMCA.com