#include "stdafx.h"
#include "sort.h"
void Selection_Sort(int a[], const int length)
{
int i, j;
int n =length;
int temp;
for (i = 0; i < n - 1; i++)
{
for (j = i; j < n; j++)
{
if (a[i] >= a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
void Bubble_Sort(int a[],int length)
{
int n = length;
int i, j, temp;
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - 1 - i; j++)
{
if (a[j] >= a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
void Quick_Sort(int a[], int low, int high)
{
if (low >= high)
{
return;
}
int first = low;
int last = high;
int key = a[low];
while (first < last)
{
while (first < last&&a[last] >= key)
{
--last;
}
a[first] = a[last];
while (first < last &&a[first] <= key)
{
++first;
}
a[last] = a[first];
}
a[first] = key;
Quick_Sort(a, low, first - 1);
Quick_Sort(a, last + 1, high);
}
#include "sort.h"
void Selection_Sort(int a[], const int length)
{
int i, j;
int n =length;
int temp;
for (i = 0; i < n - 1; i++)
{
for (j = i; j < n; j++)
{
if (a[i] >= a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
void Bubble_Sort(int a[],int length)
{
int n = length;
int i, j, temp;
for (i = 0; i < n - 1; i++)
{
for (j = 0; j < n - 1 - i; j++)
{
if (a[j] >= a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
/*
for(i=1 ; i<n ; i++)
{
for(j=n-1; j>=i;j--)
{
if(a[j]>= a[j-1])
{
int temp;
temp = a[j];
a[j] = a[j-1];
a[j-1] = temp;
}
}
}
*/
void Quick_Sort(int a[], int low, int high)
{
if (low >= high)
{
return;
}
int first = low;
int last = high;
int key = a[low];
while (first < last)
{
while (first < last&&a[last] >= key)
{
--last;
}
a[first] = a[last];
while (first < last &&a[first] <= key)
{
++first;
}
a[last] = a[first];
}
a[first] = key;
Quick_Sort(a, low, first - 1);
Quick_Sort(a, last + 1, high);
}