Ex-17 Quick Sort

  • October 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Ex-17 Quick Sort as PDF for free.

More details

  • Words: 105
  • Pages: 2
EX.NO:17

QUICK SORT

PROGRAM: #include<stdio.h> #include void swap(int a[],int j,int i); void quick(int a[],int first,int last) void main() { int a[20],n,i,f,l; clrscr(); printf("Enter the number of elements\n"); scanf("%d",&n); printf("\nEnter the elements\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); f=1; l=n; quick(a,f,l); printf("The sorted elements\n"); for(i=1;i<=n;i++) printf("%d\n",a[i]); getch(); } void swap(int a[],int i,int j) { int temp; temp=a[i]; a[i]=a[j]; a[j]=temp; } void quick(int a[],int first,int last) { int i,j,pivot; if(first=pivot&&j>first) j--;

if(i<j) swap(a,i,j); } swap(a,first,j); quick(a.first,j-1); quick(a,j+1,last); } } OUTPUT: Enter the number of elements 5 Enter the elements 32 3 5 56 21 The sorted elements 3 5 21 32 56

Related Documents

Quick Sort
May 2020 4
Quick Sort
July 2020 6
Quick Sort
June 2020 6
Quick Sort
May 2020 20
Ex-17 Quick Sort
October 2019 5
Junaid (quick Sort)
April 2020 9