Can any one send me a quick sort simple logic pogram...
its very urgent urgent 9 1696 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);
-
}
-
}
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
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
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 "Aborted(core
|
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
|
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);
}
|
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 Complexity
Average Case O(n2) 0
Worst Case O(n2) 0
(2) QUICK SORT
| |
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)
|
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 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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |