链表程序

单链表程序如下:

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
struct LinkedList
{
int data;
LinkedList* next;
};

LinkedList* root, *second, *third;
root = new LinkedList;
second = new LinkedList;
third = new LinkedList;

root->data = 10;
root->next = second;
second->data = 20;
second->next = third;
third->data = 30;
third->next = nullptr;

LinkedList* guy = new LinkedList;
guy->data = 90;
guy->next = second->next;
second->next = guy;
while(root)
{
cout<< root->data <<endl;
root = root->next;
}