//a program to implement quick sort #include<stdio.h> #include int main() { void selectionsort(int a[100],int n); int array[100]={0},n=0,c; clrscr(); printf(" Selection Sort \n"); printf("How many values do you want to enter ? : "); scanf("%d",&n); printf("\n"); for(c=0;c
//a program to implement quicksort #include<stdio.h> #include void main() { int partition(int arr[10],int beg,int end); void quicksort(int arr[10],int beg,int end); int i,arr[10],n; clrscr(); printf("\n number of elements to be sorted by quick sort: "); scanf("%d",&n); printf("\nEnter the list of numbers:-\n"); for(i=0;i
arr[j]=temp; } } temp=arr[i+1]; arr[i+1]=arr[end]; arr[end]=temp; return i+1; } void quicksort(int arr[10],int beg,int end) { int q; if(beg<end) { q=partition(arr,beg,end); quicksort(arr,beg,q-1); quicksort(arr,q+1,end); } }
//a program to implement mearge sort #include<stdio.h> #include
void merge(int arr[50],int beg,int mid,int end) { int i,j,k=0; int n1=(mid-beg)+1,n2=end-mid; int tmp1[50],tmp2[50]; for(i=0;i
//a program to implement Heap Sort #include #include<stdio.h> void build_heap(int arr[],int n); void heapify(int arr[],int i,int k); void heap_sort(int arr[],int n)
{ build_heap(arr,n); for(int i=n-1;i>=1;i--) { int t1; t1=arr[i]; arr[i]=arr[0]; arr[0]=t1; heapify(arr,0,i); } } void build_heap(int arr[],int n) { for(int i=n/2;i>=0;i--) heapify(arr,i,n); } void heapify(int arr[],int i,int k) { int larger=i; int l=((2*i)+1); int r=((2*i)+2); if((larr[larger])) larger=l; if((rarr[larger])) larger=r; if(larger!=i) { int t2; t2=arr[i]; arr[i]=arr[larger]; arr[larger]=t2; heapify(arr,larger,k); } } void main() { clrscr(); int i,p,n; int arr[50]; printf("enter the no. of element in heap :- "); scanf("%d",&n); printf("\nenter the element to be sorted:-\n"); for(i=0;i
Related Documents
More Documents from ""