Thread: how to delete duplicated numbers in quick sort ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    7

    Exclamation how to delete duplicated numbers in quick sort ?

    hallo everybody, in fact, i wrote those codes but i encountered a difficulty in how to delete the duplication for example, i intered 3 4 6 6 7 3 the output comes like that
    3 3 4 6 6 7. The questions is what are the codes that i have to add to make it like that
    3 4 6 7 and where should i add them.thanks in advance




    Code:
     #include <stdio.h>
    #include <conio.h>
    #define max6
    void quicksort (int a[] , int low , int high);
    int partition ( int a[] , int low , int high);
    void main()
    {
    int arr[max], i;
    clrscr();
    printf("enter the elements for array \n");
    for(i= 0 ; i< max; i++)
    scanf("%d", &arr[i]);
    quicksort(arr , 0 , max-1);
    printf("\n the sorted array is \n");
    for( i= 0 ; i< max ; i++)
    printf("%d" , arr[i]);
    }
    void quicksort ( int a[] , int low , int high)
    {
    int pivot;
    if(low < high)
    {
    pivot = partition ( a , low , high);
    quicksort ( a ,low , pivot - 1);
    quicksort (a , pivot + 1 , high);
    }
    }
    int partition ( int a[] , int low , int high)
    {
    int i , j , x , temp;
    x = a[high];
     i = low - 1;
    for ( j = low ; j < high; j++)
    {
    if ( a [j] <= x)
    {
    i = i+1;
    temp = a[i];
    a[i] = a[j];
    a[j] = temp;
    }
    }
    temp = a [i+1];
    a[i+1] = a[high];
    a[high] = temp;
    return (i+1);
    }
    Last edited by strawberry88; 03-12-2010 at 02:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. bubble sort not sorting numbers in order.
    By rushhour in forum C++ Programming
    Replies: 21
    Last Post: 02-19-2009, 01:40 PM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Problem need help
    By Srpurdy in forum C++ Programming
    Replies: 1
    Last Post: 07-24-2002, 12:45 PM
  5. memory management...
    By master5001 in forum Game Programming
    Replies: 24
    Last Post: 01-07-2002, 05:50 PM