访问次数:1

前插法创建单链表(逆序存储) | Wenji's blog
头部背景图片
WenJi's blog |
|

前插法创建单链表(逆序存储)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<cstdio>
#define OK 1
using namespace std;
typedef struct LNode //这个LNode不能省略
{
int data;
struct LNode *next;
}LNode,*LinkList;
bool InitList(LinkList &L)
{
L=new LNode;
L->next=NULL;
return OK;
}
int main()
{
LinkList L;
InitList(L);
LNode *p;
for(int i=0;i<5;i++)
{
p=new LNode;
cin>>p->data;
p->next=L->next;
L->next=p;
}
p=L->next;
while(p)
{
cout<<p->data<<endl;
p=p->next;
}
return 0;
}
Dear friends TRIPLANE

Not available

- 00:00 / 00:00
  1. 1 Dear friends TRIPLANE
  2. 2 Butter-Fly 和田光司
  3. 3 宵闇花火 葉月ゆら