-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLinkList.cpp
More file actions
36 lines (35 loc) · 740 Bytes
/
Copy pathLinkList.cpp
File metadata and controls
36 lines (35 loc) · 740 Bytes
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
#include<iostream>
using namespace std;
typedef int ElemType;
class LNode
{
public:
LNode(ElemType data) {
this->data = data;
this->next = NULL;
}
void add(ElemType data) {
LNode * p = this;
while(p->next)
p=p->next;
p->next = new LNode(data);
}
template<class T>
void arrayAdd(T &a) {
for(int i=0;i<sizeof(a)/sizeof(a[0]);i++) {
this->add(a[i]);
}
}
void print() {
LNode * p = this;
int count = 0;
while(p) {
cout << "LinkList["<<count<<"]:"<<p->data<<endl;
p=p->next;
count++;
}
}
ElemType data;
LNode *next;
};
typedef LNode *LinkList;