📄 sort.cpp
字号:
#include <iostream.h>
void InsertSort(int a[],n)//插入排序
{
int i,j;
int temp;
for(i = 0 ; i< n-1 ; i ++)
{
temp = a[i+1] ;
j = i;
while(j>-1&&temp<=a[j])
{
a[j +1] = a[j] ;
j--;
}
a[j+1] = temp;
}
}
void SelectSort(int a[], n) //选择排序
{
int i , j;
int temp ;
for(i = 0 ; i < n-1 ; i++)
{
small= i;
for(j = i+1; j < n; j ++)
if(a[j] < a[small]) small =j ;
if(small!= i)
{
temp = a[i] ;
a[i] = a[small];
a[small] = temp;
}
}
}
void BubbleSort(int a[],n)////冒泡排序
{
int i,j ,temp,flag =1;
for(i = 1 ; i < n&&flag ==1 ; i++)
{
flag = 0 ;
for(j = 0 ; j < n - i ; j ++)
{
if(a[j] >a[j+1])
{
flag = 1;
temp = a[j] ;
a[j] = a[j+1] ;
a[j+1] = temp ;
}
}
}
}
void quickSort(int a[], int low,int high)//////快排序
{
int i = low,j = high ,temp = a[low] ;
while(i<j)
{
while(i<j && temp <= a[j]) j --;
if(i < j)
{
a[i] = a[j] ;
i ++ ;
}
while(i<j && a[i] < temp) i++ ;
if(i < j)
{
a[j] = a[i] ;
j -- ;
}
}
a[i] = temp;
if(low<i) quickSort(a,low,i - 1);
if(i<high) quickSort(a,j+1,high);
}
int main()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -