记录一下,面试可能还有插入排序、快排的链表实现
#include<iostream>
using namespace std;
const int N = 1010;
int n;
int p[N];
void sort()
{
for (int i = 1; i < n; i ++ )
{
int temp = p[i];
int j = i - 1;
while (j >= 0 && p[j] >= temp)
{
p[j + 1] = p[j];
j --;
}
p[j + 1] = temp;
}
}
int main()
{
cin >> n;
for (int i = 0; i < n; i ++ ) cin >> p[i];
sort();
for (int i = 0; i < n; i ++ ) cout << p[i] << " ";
cout << endl;
}