#include <iostream>
#include <stdio.h>
#include<process.h>
using namespace std;
/*int a[7];//定义全局变量,这两个变量需要在子函数中使用
void quicksort(int left, int right)
{
int i, j, t, temp;
if (left>right)
return;
temp = a[left]; //temp中存的就是基准数
i = left;
j = right;
while (i != j)
{
//顺序很重要,要先从右边开始找
while (a[j] >= temp && i<j)
j--;
//再找右边的
while (a[i] <= temp && i<j)
i++;
//交换两个数在数组中的位置
if (i<j)
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
//最终将基准数归位
a[left] = a[i];
a[i] = temp;
quicksort(left, i - 1);//继续处理左边的,这里是一个递归的过程
quicksort(i + 1, right);//继续处理右边的 ,这里是一个递归的过程
}*/
int main()
{
/* for (int i = 0; i < 7; i++)
{
cin >> a[i];
}
//快速排序
quicksort(0, 6);
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
cout << a[i] << endl;
system("pause");*/
//二分法排序
/*for (int i = 1; i < sizeof(a)/sizeof(a[0]); i++)
{
int temp = a[i];
int right = i - 1;
int left = 0;
int mid;
while (left <= right)
{
mid = (left + right) / 2;
if (a[mid] > temp)
{
right = mid - 1;
}
else if (a[mid] < temp)
{
left = mid + 1;
}
}
for (int j = i; j > left; j--)
{
a[j] = a[j - 1];
}
a[left] = temp;
}
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
cout << a[i] << endl;*/
//插入排序的算法
int a[] = {15,20,3,16,145,545,20};
int j = 0;
for (int i = 1; i < sizeof(a) / sizeof(a[0]); i++)
{
int t=a[i] ;
for (j = i - 1; j >= 0 && a[j]>t; j--)
{
a[j + 1] = a[j];
}
a[j + 1] = t;
}
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
cout << a[i] << endl;
system("pause");
return 1;
}
#include <stdio.h>
#include<process.h>
using namespace std;
/*int a[7];//定义全局变量,这两个变量需要在子函数中使用
void quicksort(int left, int right)
{
int i, j, t, temp;
if (left>right)
return;
temp = a[left]; //temp中存的就是基准数
i = left;
j = right;
while (i != j)
{
//顺序很重要,要先从右边开始找
while (a[j] >= temp && i<j)
j--;
//再找右边的
while (a[i] <= temp && i<j)
i++;
//交换两个数在数组中的位置
if (i<j)
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
//最终将基准数归位
a[left] = a[i];
a[i] = temp;
quicksort(left, i - 1);//继续处理左边的,这里是一个递归的过程
quicksort(i + 1, right);//继续处理右边的 ,这里是一个递归的过程
}*/
int main()
{
/* for (int i = 0; i < 7; i++)
{
cin >> a[i];
}
//快速排序
quicksort(0, 6);
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
cout << a[i] << endl;
system("pause");*/
//二分法排序
/*for (int i = 1; i < sizeof(a)/sizeof(a[0]); i++)
{
int temp = a[i];
int right = i - 1;
int left = 0;
int mid;
while (left <= right)
{
mid = (left + right) / 2;
if (a[mid] > temp)
{
right = mid - 1;
}
else if (a[mid] < temp)
{
left = mid + 1;
}
}
for (int j = i; j > left; j--)
{
a[j] = a[j - 1];
}
a[left] = temp;
}
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
cout << a[i] << endl;*/
//插入排序的算法
int a[] = {15,20,3,16,145,545,20};
int j = 0;
for (int i = 1; i < sizeof(a) / sizeof(a[0]); i++)
{
int t=a[i] ;
for (j = i - 1; j >= 0 && a[j]>t; j--)
{
a[j + 1] = a[j];
}
a[j + 1] = t;
}
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++)
cout << a[i] << endl;
system("pause");
return 1;
}