数组模拟链表

 1 #include<iostream>
 2 using namespace std;
 3 struct lb{
 4     int data;
 5     int next;
 6 }a[15];
 7 int main()
 8 {
 9     int n, x;
10     cin>>n;
11     for(int i=1; i<=n; i++)
12     {
13         cin>>x;
14         a[i].data=x;
15         if(i!=n)
16         {
17             a[i].next=i+1;
18         }
19     }
20     a[n].next=0;
21     //输出 链表 
22     for(int i=1 ;i ;i=a[i].next)cout<<a[i].data<<" ";
23     cout<<endl;
24     //删除第3个元素后输出链表 
25     a[2].next=a[3].next;
26     for(int i=1 ;i ;i=a[i].next)cout<<a[i].data<<" ";
27     cout<<endl;
28     // 在第4个元素后插入100后输出链表 
29     a[n+1].data=100;
30     a[n+1].next=0;
31     
32     a[n+1].next=a[4].next;
33     a[4].next=n+1;
34     for(int i=1 ;i ;i=a[i].next)cout<<a[i].data<<" ";
35     
36     return 0;
37 } 

 相关练习题《围圈报数》:http://ybt.ssoier.cn:8088/problem_show.php?pid=1334

什么是链式前向星?

初学链式前向星

深度理解链式前向星

转载于:https://www.cnblogs.com/tflsnoi/p/11280731.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值