c/c++:单向链表顺序输出
数据结构实验之链表一:顺序建立链表 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
36
37
38
39
40
41
42
43
44
using namespace std;
struct node
{
int data;
struct node *next;
};
int main ()
{
std::ios::sync_with_stdio(false);
struct node *head, *tail, *p;
head = new node;
head->next = NULL;
tail = head;
int N ;
int tmpN;
cin>>N;
{
tmpN = N;
while(tmpN--)
{
p = new node;
p->next = NULL;
cin >> p->data ;
tail->next = p;
tail = p;
}
p = head->next;
while(p->next!=NULL)
{
cout<<p->data<<' ';
p=p->next;
}
cout<<p->data<<' ';
cout<<endl;
}
return 0;
}