数组模拟链表

 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/ivanovcraft/p/9037475.html

什么是链式前向星?

初学链式前向星

深度理解链式前向星

原文地址:https://www.cnblogs.com/tflsnoi/p/11280731.html