数组模拟链表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数组模拟链表相关的知识,希望对你有一定的参考价值。

 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 }

 

以上是关于数组模拟链表的主要内容,如果未能解决你的问题,请参考以下文章