-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_List_test.cpp
58 lines (50 loc) · 1002 Bytes
/
my_List_test.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
#include<iostream>
using namespace std;
typedef int DataType
//关于结点的结构体的创建
struct ListNode{
ListNode* _next;
ListNode* _prev;
DataType _data;
};
class List{
typedef ListNode Node;
public:
//构造函数
List():_head->_data(1){
_head = new Node;
_head->next = _head;
_head->prev = _head;
}
//成员函数
//插入函数默认从尾部插入
void insert(DataType x){
new_node = new Node;
_head->prev->next = new_node;
new_node->prev = _head->prev;
_head->prev = new_node;
new_node->next = _head;
}
//显示函数
void print(){
Node* cur = _head->next;
while(cur != _head){
cout<<cur->_data<<" ";
}
cout<<endl;
}
private:
Node* _head;
}
void Test(){
List Li;
//Li.insert(1);
//Li.insert(2);
//Li.insert(3);
//Li.insert(4);
//Li.print();
}
int main(){
Test();
return 0;
}