-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinked_list.h
More file actions
62 lines (48 loc) · 1.38 KB
/
Copy pathLinked_list.h
File metadata and controls
62 lines (48 loc) · 1.38 KB
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
#include <stdio.h>
template<typename T> struct list_elem {
T info;
struct list_elem<T> *next, *prev;
};
template <typename T> class LinkedList {
public:
struct list_elem<T> *pfirst, *plast;
void addFirst(T x) {
struct list_elem<T> *paux;
paux = new struct list_elem<T>;
paux->info = x;
paux->prev = NULL;
paux->next = pfirst;
if (pfirst != NULL) pfirst->prev = paux;
pfirst = paux;
if (plast==NULL) plast=pfirst;
}
void addLast(T x) {
struct list_elem<T> *paux;
paux = new struct list_elem<T>;
paux->info = x;
paux->prev = plast;
paux->next = NULL;
if (plast != NULL) plast->next = paux;
plast = paux;
if (pfirst == NULL) pfirst = plast;
}
LinkedList() {
pfirst = plast = NULL;
}
int isEmpty() {
if (pfirst == plast == NULL)
return 1;
else return 0;
}
void deleteFirst() {
struct list_elem<T> *aux;
aux = new struct list_elem<T>;
if (pfirst != NULL) {
aux = pfirst->next;
delete(pfirst);
pfirst=aux;
if (pfirst != NULL)
pfirst->prev=NULL;
}
}
};