Quick Sort

# Quick Sort - } void display(int a,int n) { int i;

This preview shows pages 1–3. Sign up to view the full content.

#include<stdio.h> #include<conio.h> /* RISHI AGARWAL             QUICK SORT    ROLL NO 02    SE CMPN A */ #define max 10 void swap(int *m,int *n) {  int t;  t=*m;  *m=*n;  *n=t; } int partition(int arr[],int lower,int upper) {  int i,j,pivot;  pivot=arr[lower];  i=lower;  j=upper;  while(j>i)  {   i++;   j--;   if(j>i)   swap(&arr[i],&arr[j]);  }  swap(&arr[lower],&arr[j]);  return j; } void qsort(int arr[],int lower,int upper) {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
int p;  if(upper>lower)  {   p=partition(arr,lower,upper);   qsort(arr,lower,p-1);   qsort(arr,p+1,upper);  }
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } void display(int a,int n) { int i; printf("\nLIST\n"); for(i=0;i<n;i++) printf("%d ",a[i]); } void main() { int n,i,arr[max]; clrscr(); printf("Enter the no of data:"); scanf("%d",&n); printf("Enter the nos"); for(i=0;i<n;i++) scanf("%d",&arr[i]); //Displaying List display(arr,n); //Quick Sort qsort(arr,0,n-1); //Displaying Sorted List display(arr,n); getch(); } OUTPUT: Enter the no of data:10 Enter the nos100 80 90 70 50 60 10 40 30 20 LIST 100 80 90 70 50 60 10 40 30 20 LIST 10 20 30 40 50 60 70 80 90 100...
View Full Document

## This note was uploaded on 10/25/2010 for the course CMPN SEM4 taught by Professor Thakur during the Spring '07 term at University of Mumbai.

### Page1 / 3

Quick Sort - } void display(int a,int n) { int i;

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online