-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDuelLinkList.cpp
78 lines (70 loc) · 1.28 KB
/
DuelLinkList.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
using namespace std;
typedef struct DuLNode
{
int data;
struct DuLNode * prior;
struct DuLNode * next;
}DuLNode, *DuLinkList;
DuLinkList CreatDuLinkList()
{
int cnt = 0;
cout << "please input the number of the Nodes you want to creat:";
cin >> cnt;
if(!cnt)
{
return NULL;
}
DuLinkList head = new DuLNode;
DuLinkList p1 = head;
for(int i=1; i<cnt; i++)
{
DuLinkList p2 = new DuLNode;
p1->next = p2;
p2->prior = p1;
p1 = p1->next;
}
p1->next = head;
head->prior = p1;
return head;
}
void InputData(DuLinkList head)
{
DuLinkList pt = head;
if(!pt)
{
return;
}
cout << "please input datas:";
cin >> pt->data;
pt = pt->next;
while(pt!=head)
{
cout << "please input datas:";
cin >> pt->data;
pt = pt->next;
}
}
void DisplayData(DuLinkList head)
{
DuLinkList pt = head;
if(!pt)
{
return;
}
cout << pt->data << endl;
pt = pt->next;
while(pt!=head)
{
cout << pt->data << endl;
pt = pt->next;
}
}
int main()
{
DuLinkList head1 = CreatDuLinkList();
InputData(head1);
DuLinkList head2 = CreatDuLinkList();
InputData(head2);
return 0;
}