#include <iostream> using namespace std ; int main() { int n ; cin >> n ; int a[n] ; for ( int i = 0 ; i < n ; ++i) cin>>a[i] ; bool flag = false ; int temp = a[n-1]; for ( int i = n-2 ; i >= 0 ;--i) { if (a[i]>temp) { a[i+1] = a[i] ; for (int j = 0 ; j <n; ++j) cout << a[j] << " " ; cout << endl ; if (i==0) { a[i] = temp ; //a[i] = temp ; for (int j = 0 ; j <n; ++j) cout << a[j] << " " ; cout << endl ; } } else { a[i+1] = temp ; temp = a[i] ; for (int j = 0 ; j <n; ++j) cout << a[j] << " " ; cout << endl ; break ; } } return 0 ; }
这是insert排序的 初步 排序,这里面 把最后一个当做了哨兵,然后 与前面的元素相比较 。。。