数组模拟链表
1 #include <iostream> 2 3 using namespace std; 4 5 int a[100010], r[100010]; 6 int n, len, t; 7 8 int main(){ 9 cin >> n; 10 for(int i = 1; i <= n; i ++) cin >> a[i]; 11 len = n; 12 for(int i = 1; i <= n; i ++){ 13 if(i != n) r[i] = i + 1; 14 else r[i] = 0; 15 } 16 len ++; 17 cin >> a[len]; 18 t = 1; 19 while(t != 0){ 20 if(a[r[t]] > a[len]){ 21 r[len] = r[t]; 22 r[t] = len; 23 break; 24 } 25 t = r[t]; 26 } 27 t = 1; 28 while(t != 0){ 29 cout << a[t]; 30 t = r[t]; 31 } 32 return 0; 33 }