Can any one send me a quick sort simple logic pogram...
its very urgent urgent 9 1674 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?
Why don't you try to write one yourself? Do you know the algorithm?
- public class QuickSort {
-
int i; // Array index
-
-
int j; // Array index
-
-
/**
-
* @precondition Unsorted elements
-
* @postcondition Sorted elements
-
* @param qsArrays
-
* @param len
-
*/
-
public void setQuickSort(int qsArrays[], int len) {
-
setQuicksort(qsArrays, 0, len - 1);
-
}
-
-
private void setQuicksort(int qsArrays[], int left, int right) {
-
int middle = left;
-
-
//block where array division starts
-
swap(qsArrays, left, (left + right) / 2);
-
for (int i = left + 1; i <= right; i++) {
-
if (qsArrays[i] <= qsArrays[left]) {
-
middle++;
-
//recursive function for swap
-
swap(qsArrays, i, middle);
-
}
-
}
-
-
//recursive method o divide array into its child
-
swap(qsArrays, left, middle);
-
-
// Blockfor soerting arrays after the list is divided into sub array
-
if (left + 1 < middle) {
-
setQuicksort(qsArrays, left, middle - 1);
-
}
-
-
if (middle + 1 < right) {
-
setQuicksort(qsArrays, middle + 1, right);
-
}
-
} // end setQuicksort
-
-
/**
-
* Swap numbers
-
*
-
* @param list
-
* @param a
-
* @param b
-
*/
-
private void swap(int list[], int a, int b) {
-
int temp = list[a]; //temp holds first number
-
list[a] = list[b]; //first index holds a value second index
-
list[b] = temp; // second index value holds a value of temp variable
-
}
-
-
/**
-
* The main method illustrates the use of a quick sort to sort a
-
* small array with 5 values
-
* @precondition: (None)
-
* @Postcondition: Sorted Array
-
*/
-
public static void main(String str[]) {
-
//array Initialization
-
int[] qsArrays = new int[5];
-
-
//insert elements into array
-
qsArrays[0] = 20;
-
qsArrays[1] = 10;
-
qsArrays[2] = 50;
-
qsArrays[3] = 100;
-
qsArrays[4] = 05;
-
-
// Print the array before sorting:
-
System.out.println("Data before Soring ");
-
System.out.println("**************** ");
-
-
//block to print unsorted elements
-
for (int val = 0; val < 5; val++) {
-
System.out.println("Value at index" + val + " = " + qsArrays[val]);
-
}
-
-
QuickSort acc = new QuickSort();
-
acc.setQuickSort(qsArrays, 5); //calling setQuickSort method
-
-
System.out.println(" ");
-
System.out.println(" ");
-
System.out.println("Data After Soring");
-
System.out.println("****************");
-
-
//block to print sorted elements
-
for (int val = 0; val < 5; val++) {
-
System.out.println("Value at index" + val + " = " + qsArrays[val]);
-
}
-
}
-
}
-
this is complex... i need simple.....
...
this is complex... i need simple.....
Here ya go: - public class ReallyQuickSort {
-
-
static void display(String message, int[] array) {
-
System.out.print(message);
-
for(int i = 0; i < array.length; i++) {
-
System.out.print(array[i]+" ");
-
}
-
}
-
-
static void sort(int[] array) {
-
java.util.Arrays.sort(array);
-
}
-
-
public static void main(String[] args) {
-
int[] array = {20, 10, 50, 100, 5};
-
display("Before sorting: ", array);
-
sort(array);
-
display("\nAfter sorting: ", array);
-
}
-
}
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
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
Here ya go: - public class ReallyQuickSort {
-
-
static void display(String message, int[] array) {
-
System.out.print(message);
-
for(int i = 0; i < array.length; i++) {
-
System.out.print(array[i]+" ");
-
}
-
}
-
-
static void sort(int[] array) {
-
java.util.Arrays.sort(array);
-
}
-
-
public static void main(String[] args) {
-
int[] array = {20, 10, 50, 100, 5};
-
display("Before sorting: ", array);
-
sort(array);
-
display("\nAfter sorting: ", array);
-
}
-
}
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,...
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.
No, I'm done helping you.
ok promo.... i am workin ion that sort to make it simple will be complet it by evening
ok promo.... i am workin ion that sort to make it simple will be complet it by evening
Please tell us how it goes.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
...
|
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...
|
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?
|
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...
|
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 ...
|
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!
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
| |