Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include<stdio.h>
void mergesort(int [],int,int);
void merge(int [],int,int,int);
int main()
{
int arr[20],i,n;
printf("Enter the number of eleemnts u want 2 store in the array:\t");
scanf("%d",&n);
printf("\nEnter the array elements:\n");
for(i=0;i<n;i++)
{
printf("\narr[%d]=",i);
scanf("%d",&arr[i]);
}
printf("\nBefore sorting the array elements are:\n");
for(i=0;i<n;i++)
{
printf("%d\t",arr[i]);
}
printf("\n\nAfter sorting the array elements are:\n");
mergesort(arr,0,n-1);
for(i=0;i<n;i++)
{
printf("%d\t",arr[i]);
}
return 0;
}
void mergesort(int a[],int p,int r)
{
int q;
if(p<r)
{
q=(p+r)/2;
mergesort(a,p,q);
mergesort(a,q+1,r);
merge(a,p,q,r);
}
}//end of mergesort()
return 0;
}
void quicksort(int a[],int p,int r)
{
int q;
if(p<r)
{
q=partition(a,p,r);
quicksort(a,p,q-1);
quicksort(a,q+1,r);
}
}//end of quicksort()
return (i+1);
}//end of partition()