Sorts
Sorts
temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
insertion sort
a[j] = index;
}
}
heap sort
root = maxchild;
}
}
bubble sort
quick sort
#include <stdio.h>
void swap(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void quicksort(int list[],int m,int n)
{
int key,i,j,k;
if( m < n)
{
k = ((m+n)/2; // choosing pivot element
swap(&list[m],&list[k]);
key = list[m];
i = m+1;
j = n;
while(i <= j)
{
while((i <= n) && (list[i] <= key))
i++;
while((j >= m) && (list[j] > key))
j--;
if( i < j)
swap(&list[i],&list[j]);
}
swap(&list[m],&list[j]);
// recursively sort the lesser list
quicksort(list,m,j-1);
quicksort(list,j+1,n);
}
}