-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck2.cpp
More file actions
97 lines (73 loc) · 1.86 KB
/
check2.cpp
File metadata and controls
97 lines (73 loc) · 1.86 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>
using namespace std;
struct ListNode{
ListNode* next;
ListNode* prev;
char data;
ListNode(char d = '\0' , ListNode* n = NULL , ListNode* p = NULL){
data = d;
next = n;
prev = p;
}
};
class List{
public:
ListNode* head;
ListNode* tail;
List(ListNode* h =NULL , ListNode* t = NULL){
head = h;
tail = t;
}
void append(char c) {
if (isEmpty()) {
head = new ListNode(c);
tail = head;
return;
}
ListNode* add = new ListNode(c);
tail->next = add;
add->prev = tail;
tail = add;
}
void remove(){
if(isEmpty()) return;
ListNode* temp = tail;
tail = tail->prev;
if (tail != NULL) {
tail->next = NULL;
}
delete temp;
if(tail == NULL) {
head = NULL;
}
}
bool isEmpty(){
return head == NULL;
}
void display(){
ListNode* temp = head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp = temp->next;
}
cout<<endl;
}
};
int main() {
List myList;
myList.append('a');
myList.append('b');
myList.append('c');
cout << "List after appending a, b, c: ";
myList.display();
myList.remove();
cout << "List after removing last element: ";
myList.display();
myList.remove();
cout << "List after removing last element: ";
myList.display();
myList.remove();
cout << "List after removing last element: ";
myList.display();
return 0;
}