• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
巅峰主公
博客园    首页    新随笔    联系   管理    订阅  订阅

数组模拟链表

 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 }

 

posted @ 2017-09-20 17:53  一个天才  阅读(188)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3