-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.cpp
More file actions
45 lines (38 loc) · 813 Bytes
/
Copy pathLinkedList.cpp
File metadata and controls
45 lines (38 loc) · 813 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
37
38
39
40
41
42
43
44
45
#include "LinkedList.h"
LinkedList::LinkedList() {
head = tail = nullptr;
}
void LinkedList::insertAtEnd(int x) {
node* temp = new node();
temp->next = nullptr;
temp->value = x;
if (head == nullptr) {
head = tail = temp;
} else {
tail->next = temp;
tail = temp;
}
}
void LinkedList::insertAtStart(int x) {
node* temp = new node();
temp->next = nullptr;
temp->value = x;
if (head == nullptr) {
head = tail = temp;
} else {
temp->next = head;
head = temp;
}
}
void LinkedList::deleteFirst() {
if (head) {
node* temp = head;
head = head->next;
delete temp;
if (head == nullptr)
tail = nullptr;
}
}
bool LinkedList::isEmpty() {
return head == nullptr;
}