473,799 Members | 2,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help on quick sort - v.Urgent

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

its very urgent urgent
May 22 '07 #1
9 1696
r035198x
13,262 MVP
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
needhelp123
21 New Member
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 Recognized Expert New Member
...

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 Recognized Expert MVP
this is complex... i need simple.....
That quicksort implementation is as simple as they come. Don't just try to scrape
"TeH CoDeZ!!!11eleve n UGRENT" from the internet; think for yourself instead.

kind regards,

Jos
May 22 '07 #5
needhelp123
21 New Member
That quicksort implementation is as simple as they come. Don't just try to scrape
"TeH CoDeZ!!!11eleve n 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
needhelp123
21 New Member
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 Recognized Expert New Member
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
needhelp123
21 New Member
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 MVP
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
2927
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 "Aborted(core
0
3704
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 The article works well with CStringArray. But when I wrote the following code about double type. It does not work for
5
3793
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 List<RoleData> GetRoles() { return GetRoles(null, false); }
5
1673
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
3356
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 Complexity Average Case O(n2) 0 Worst Case O(n2) 0 (2) QUICK SORT
0
3967
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 Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
1
1704
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
16639
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 bubble sort(use when we have to 100 items: bubble sort is effective),shell sort is effective when one has to sort near abt 5000 items..selection sort is effective for sorting 1000 items...and more than 1000 and less than 5000 items if u have to sort use...
0
10482
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10225
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.