//Insertsort
template <typename Type)
void Insertsort(Type k[],int n)
{
int i;
int j;
Type temp;
for(i = 1; i<n; i++)
{
temp = k[i];
j = i-1;
while(j>=0 && temp<k[j])
{
k[j+1] = k[j--];
}
k[j+1] = temp;
}
}
//SelectSort
template <typename Type>
void SelectSort(Type k[], int n)
{
int i,j,d;
type temp;
for(i = 0; i< n; i++)
{
d = i;
for(j=i+1; j<n; j++)
if(k[j] > k[d])
d = j;
if(d != i)
{
temp = k[d];
k[d] = k[i];
k[i] = temp;
}
}
}
//Bubblesort
templatr <typename Type>
void Bubblesort(Type k[], int n)
{
int i = n;
int j;
int flag = 1;
Type temp;
while(i>0 && flag == 1)
{
flag = 0;
for(j = 0; j<n; j++)
{
if(k[j] < k[j+1])
{
flag = 1;
temp = k[j];
k[j] = k[j+1];
k[j+1] = temp;
}
}
i--;
}
}
void quicksort(int num[], int lower, int upper)
{
int pivot;
int partition(int [], int, int);
pivot = partition(num, lower, upper);
if (lower < pivot)
quicksort(num, lower, pivot - 1);
if (upper > pivot)
quicksort(num, pivot + 1, upper);
return;
}
int partition(int num[], int left, int right)
{
int pivot, temp;
pivot = num[left]; /* "capture" the pivot value, which frees up one slot */
while (left < right)
{
/* scan from right to left */
while(num[right] >= pivot && left < right) /* skip over larger or equal values */
right--;
if (right != left)
{
num[left] = num[right]; /* move the higher value into the available slot */
left++;
}
/* scan from left to right */
while (num[left] <= pivot && left < right) /* skip over smaller or equal values */
left++;
if (right != left)
{
num[right] = num[left]; /* move lower value into the available slot */
right-- ;
}
}
num[left] = pivot; /* move pivot into correct position */
return(left); /* return the pivot index */
}