C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-18-2008, 09:18 PM   #1
Registered User
 
Join Date: Sep 2008
Posts: 7
Exclamation Quick sort in C language (Program required)

I know what is Bubble sort but can anyone please tell me what exaclty is Quick Sort and i also wanted a program for it, thankz in advance
internet_bug is offline   Reply With Quote
Old 09-18-2008, 09:21 PM   #2
Registered User
 
Join Date: Oct 2006
Location: Canada
Posts: 848
no one is going to "give you a program for it". anyways, theres no "QuickSort_v1.exe". its an algorithm, not a program. theres a website called wikipedia (sorry i forget the link, google it may be able to find it). search quicksort there and you will get all you need to know.

also note that there is a one-to-one correspondence of the amount of work you spend on your post and the quality of responses.
nadroj is offline   Reply With Quote
Old 09-18-2008, 09:30 PM   #3
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,202
Since you can find out how quick sort works using the internet, I'll leave finding the details to you. But quick sort usually works by selecting a pivot value, then partitioning the array around the value. (Partitions are guaranteed to place at least one element in its sorted position.) Do this recursively, and after every element has been selected as a pivot, then the sequence is sorted.

Now, C implemented the quick sort algorithm for you:

Code:
#include <stdlib.h>

int compare (const void * a, const void * b)
{
   const int * c = a;
   const int * d = b;
   
   if (*c < *d)
      return -1;
   else if (*c > *d)
      return 1;
   else
      return 0;
}


int main ()
{
   int sortme[] = {6, 4, 8, 5, 1, 2, 3, 7, 9,};
   
   qsort(sortme, 9, sizeof(int), compare);
   return 0;
}
__________________
Os iusti meditabitur sapientiam
Et lingua eius loquetur indicium

"There is nothing either good or bad, but thinking makes it so." (Shakespeare, Hamlet, Act II scene ii)

http://www.myspace.com/whiteflags99
whiteflags is offline   Reply With Quote
Old 09-18-2008, 10:48 PM   #4
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
http://www.cs.ubc.ca/spider/harrison...ting-demo.html
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 09-18-2008, 11:18 PM   #5
Registered User
 
Join Date: Sep 2008
Posts: 7
Quote:
Originally Posted by nadroj View Post
no one is going to "give you a program for it". anyways, theres no "QuickSort_v1.exe". its an algorithm, not a program. theres a website called wikipedia (sorry i forget the link, google it may be able to find it). search quicksort there and you will get all you need to know.

also note that there is a one-to-one correspondence of the amount of work you spend on your post and the quality of responses.
thankz for the site, it's www.wikipedia.net, great site it provided a lot of info

Quote:
Originally Posted by citizen View Post
Since you can find out how quick sort works using the internet, I'll leave finding the details to you. But quick sort usually works by selecting a pivot value, then partitioning the array around the value. (Partitions are guaranteed to place at least one element in its sorted position.) Do this recursively, and after every element has been selected as a pivot, then the sequence is sorted.

Now, C implemented the quick sort algorithm for you:

Code:
#include <stdlib.h>

int compare (const void * a, const void * b)
{
   const int * c = a;
   const int * d = b;
   
   if (*c < *d)
      return -1;
   else if (*c > *d)
      return 1;
   else
      return 0;
}


int main ()
{
   int sortme[] = {6, 4, 8, 5, 1, 2, 3, 7, 9,};
   
   qsort(sortme, 9, sizeof(int), compare);
   return 0;
}
millions of thankz mate

Quote:
Originally Posted by Salem View Post

excelelnt site M8, this will be quite useful to me
internet_bug is offline   Reply With Quote
Reply

Tags
quick, sort

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
another sort useless program mrsirpoopsalot C Programming 21 09-18-2006 02:35 AM
How to fix misaligned assignment statements in the source code? biggyK C++ Programming 28 07-16-2006 11:35 PM
Quick sort Saiyanman C Programming 4 07-30-2002 10:16 PM
bubble sort in assembly language!!!!!! lorenzohhh C++ Programming 1 04-15-2002 08:30 PM
Hey guys I ned some quick help here with a little program, please. Desperado C++ Programming 34 11-26-2001 01:17 PM


All times are GMT -6. The time now is 08:54 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22