#include<iostream>
using namespace std;
struct node {
int val;
int pre;
int next;
};
node a[100];
int n;
int head = 1;
int tail = n;
void printstaticlist()
{
int p = head;
while (p)
{
cout << a[p].val << " ";
p = a[p].next;
}
}
void printstaticlist2()
{
int p = tail;
while (p)
{
cout << a[p].val << " ";
p = a[p].pre;
}
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i].val;
a[i].next = i + 1;
a[i].pre = i - 1;
}
a[n].next = 0; a[1].pre = 0;
a[0].val = 0; a[n + 1].val = 0;
head = 1; tail = n;
printstaticlist();
cout << endl;
printstaticlist2();
return 0;
}
数组模拟静态链表
最新推荐文章于 2024-08-31 15:48:32 发布