Quick sort in C language (Program required)

This is a discussion on Quick sort in C language (Program required) within the C Programming forums, part of the General Programming Boards category; I know what is Bubble sort but can anyone please tell me what exaclty is Quick Sort and i also ...

  1. #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

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    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.

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    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;
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,834
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #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


    excelelnt site M8, this will be quite useful to me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another sort useless program
    By mrsirpoopsalot in forum C Programming
    Replies: 21
    Last Post: 09-18-2006, 03:35 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Quick sort
    By Saiyanman in forum C Programming
    Replies: 4
    Last Post: 07-30-2002, 11:16 PM
  4. bubble sort in assembly language!!!!!!
    By lorenzohhh in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2002, 09:30 PM
  5. Replies: 34
    Last Post: 11-26-2001, 01:17 PM

Tags for this Thread


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