void swap(int k[],int i, int j)
{
int temp;
temp = k[i];
k[i]=k[j];
k[j]=temp;
}
void HeapSort(int k[],int n)
{
int i;
for(i=n/2;i>0;i--)
{
Heapadjust(k,i,n);
}
for(i=n;i>1;i--)
{
swap(k,1,i)
Heapadjust(k,1,i-1);
}
}
void Heapadjust(int k[],int s,int n)
{
int i,temp=k[s] ;
for(i=2*s;i<=n;i*=2)
{
if(i<n && k[i]<k[i+1])
{
i++;
}
if (temp >= k[i])
{
break;
}
k[s] =k[i];
s=i;
}
k[s]=temp;
}
6.MergeSort
define Maxsize 10
Merge(int*list1,int list_size1,int*list2,int list_size2)
{
int temp[Maxsize];
int i=j=k=0;
while(i<list_size1 && j<list_size2)
{
if(list1[i]<list2[j])
temp[k++]=list1[i++];
else
temp[k++]=list2[j++];
while(i<list_size1)
temp[k++]=list1[i++];
while(j<list_size2)
temp[k++]=list1[j++];
for(int n=0;n<list_size1+list_size2;n++)
{
list1[n]=temp[n];
}
}
}
Mergesort(int k[],int n)
{
int *list1 = k;
int list_size1=n/2;
int *list2 = k+list_size1;
int list_size2=n-list_size1;
Mergesort(list1,list_size1);
Mergesort(list2,list_size2);
Merge(list1,list_size1,list2,list_size2);
}
7.QuickSort
int partition(int k[],int low,int high)
{
int point;
point=k[low];
while(low<high)
{
while(low<high&&k[high]>=point)
{
high--;
}
swop(k,point,k[high]);
while(low<high&&k[low]<=point)
{
low++;
}
swop(k,point,k[low]);
}
return low;
}
void Qsort(int k[],int low,int high)
{
int point;
if(low<high){
point = partition(k,low,high);
Qsort(k,low,point-1);
Qsort(k,point+1,high)
}
}
QuickSort(int k[],int n)
{
Qsort(int k[],0,int n);
}