473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need help on quick sort - v.Urgent

needhelp123
Can any one send me a quick sort simple logic pogram...

its very urgent urgent
May 22 '07 #1
9 1674
r035198x
13,262 8TB
Can any one send me a quick sort simple logic pogram...

its very urgent urgent
Why don't you try to write one yourself? Do you know the algorithm?
May 22 '07 #2
Why don't you try to write one yourself? Do you know the algorithm?
Expand|Select|Wrap|Line Numbers
  1.  public class QuickSort { 
  2. int i; // Array index
  3.  
  4. int j; // Array index
  5.  
  6. /**
  7. * @precondition Unsorted elements
  8. * @postcondition Sorted elements
  9. * @param qsArrays
  10. * @param len
  11. */
  12. public void setQuickSort(int qsArrays[], int len) {
  13. setQuicksort(qsArrays, 0, len - 1);
  14. }
  15.  
  16. private void setQuicksort(int qsArrays[], int left, int right) {
  17. int middle = left;
  18.  
  19. //block where array division starts
  20. swap(qsArrays, left, (left + right) / 2);
  21. for (int i = left + 1; i <= right; i++) {
  22. if (qsArrays[i] <= qsArrays[left]) {
  23. middle++;
  24. //recursive function for swap
  25. swap(qsArrays, i, middle);
  26. }
  27. }
  28.  
  29. //recursive method o divide array into its child
  30. swap(qsArrays, left, middle);
  31.  
  32. // Blockfor soerting arrays after the list is divided into sub array
  33. if (left + 1 < middle) {
  34. setQuicksort(qsArrays, left, middle - 1);
  35. }
  36.  
  37. if (middle + 1 < right) {
  38. setQuicksort(qsArrays, middle + 1, right);
  39. }
  40. } // end setQuicksort
  41.  
  42. /**
  43. * Swap numbers
  44. * @param list
  45. * @param a
  46. * @param b
  47. */
  48. private void swap(int list[], int a, int b) {
  49. int temp = list[a]; //temp holds first number
  50. list[a] = list[b]; //first index holds a value second index
  51. list[b] = temp; // second index value holds a value of temp variable 
  52. }
  53.  
  54. /**
  55. * The main method illustrates the use of a quick sort to sort a 
  56. * small array with 5 values
  57. * @precondition: (None)
  58. * @Postcondition: Sorted Array
  59. */
  60. public static void main(String str[]) {
  61. //array Initialization
  62. int[] qsArrays = new int[5];
  63.  
  64. //insert elements into array
  65. qsArrays[0] = 20;
  66. qsArrays[1] = 10;
  67. qsArrays[2] = 50;
  68. qsArrays[3] = 100;
  69. qsArrays[4] = 05;
  70.  
  71. // Print the array before sorting:
  72. System.out.println("Data before Soring ");
  73. System.out.println("**************** ");
  74.  
  75. //block to print unsorted elements
  76. for (int val = 0; val < 5; val++) {
  77. System.out.println("Value at index" + val + " = " + qsArrays[val]);
  78. }
  79.  
  80. QuickSort acc = new QuickSort();
  81. acc.setQuickSort(qsArrays, 5); //calling setQuickSort method
  82.  
  83. System.out.println(" ");
  84. System.out.println(" ");
  85. System.out.println("Data After Soring");
  86. System.out.println("****************");
  87.  
  88. //block to print sorted elements
  89. for (int val = 0; val < 5; val++) {
  90. System.out.println("Value at index" + val + " = " + qsArrays[val]);
  91. }
  92. }
  93. }
  94.  
this is complex... i need simple.....
May 22 '07 #3
prometheuzz
197 Expert 100+
...

this is complex... i need simple.....
Here ya go:

Expand|Select|Wrap|Line Numbers
  1. public class ReallyQuickSort {
  2.  
  3.     static void display(String message, int[] array) {
  4.         System.out.print(message);
  5.         for(int i = 0; i < array.length; i++) {
  6.             System.out.print(array[i]+" ");
  7.         }
  8.     }
  9.  
  10.     static void sort(int[] array) {
  11.         java.util.Arrays.sort(array);
  12.     }
  13.  
  14.     public static void main(String[] args) {
  15.         int[] array = {20, 10, 50, 100, 5};
  16.         display("Before sorting: ", array);
  17.         sort(array);
  18.         display("\nAfter sorting:  ", array);
  19.     }
  20. }
May 22 '07 #4
JosAH
11,448 Expert 8TB
this is complex... i need simple.....
That quicksort implementation is as simple as they come. Don't just try to scrape
"TeH CoDeZ!!!11eleven UGRENT" from the internet; think for yourself instead.

kind regards,

Jos
May 22 '07 #5
That quicksort implementation is as simple as they come. Don't just try to scrape
"TeH CoDeZ!!!11eleven UGRENT" from the internet; think for yourself instead.

kind regards,

Jos
do not try to put down any one if u know the concept let me.. kno that program is designed by me.....
thank you
May 22 '07 #6
Here ya go:

Expand|Select|Wrap|Line Numbers
  1. public class ReallyQuickSort {
  2.  
  3.     static void display(String message, int[] array) {
  4.         System.out.print(message);
  5.         for(int i = 0; i < array.length; i++) {
  6.             System.out.print(array[i]+" ");
  7.         }
  8.     }
  9.  
  10.     static void sort(int[] array) {
  11.         java.util.Arrays.sort(array);
  12.     }
  13.  
  14.     public static void main(String[] args) {
  15.         int[] array = {20, 10, 50, 100, 5};
  16.         display("Before sorting: ", array);
  17.         sort(array);
  18.         display("\nAfter sorting:  ", array);
  19.     }
  20. }
promo,
before itself i couild have used tahat redimade util package,,,,

i asked would i be possible for you to update that,,, i mean simler by using the concep what i have,...
May 22 '07 #7
prometheuzz
197 Expert 100+
promo,
before itself i couild have used tahat redimade util package,,,,

i asked would i be possible for you to update that,,, i mean simler by using the concep what i have,...
No, I'm done helping you.
May 22 '07 #8
No, I'm done helping you.

ok promo.... i am workin ion that sort to make it simple will be complet it by evening
May 22 '07 #9
r035198x
13,262 8TB
ok promo.... i am workin ion that sort to make it simple will be complet it by evening
Please tell us how it goes.
May 23 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Eva | last post by:
Hi, I try to implement quick sort. I sort vectors by their first value. 10 2 3 4 9 3 5 6 10 4 5 6 must be 9 3 5 6 10 2 3 4 10 4 5 6 The prog works great on maybe 500 vectors, but I have an...
0
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 ...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
5
by: Vikas Kumar | last post by:
Hi, I'm not able to convert the following dll import statement in C# to VB.NET. Can any one please help me in this respect?
1
by: jmbn2k | last post by:
HI Can anyone get me the code for the Big-O-Notation implementation of Quick sort and Bubble Sort........please (1) BUBBLE SORT Bubble Sort Time Complexity Space...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
1
by: AngelLopez1989 | last post by:
I need the complete C++ program/ algorithm of Quick Sort. Can you please help me out? No pseudocode please. Can you please also explain how to do the quick sort? Thank you!
5
by: neehakale | last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort. I got an idea,in which situation we can use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.