-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_class.cpp
More file actions
154 lines (151 loc) · 4.29 KB
/
Copy pathnode_class.cpp
File metadata and controls
154 lines (151 loc) · 4.29 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//
// Created by mel on 28.01.2020.
//
#include "node_class.h"
#include <iostream>
using namespace std;
//using doubleLinkedList<T>;
template <typename T>
void doubleLinkedList<T>::addItem(T val) {
if (head == nullptr) {
head = new node <T>;
head->data = val;
tail = head;
}
else {
tail->next = new node <T>;
tail->next->previous = tail;
tail = tail->next;
tail->data = val;
tail->next = nullptr;
}
}
template <typename T>
void doubleLinkedList<T>::print_list() {
node <T> *current = head;
cout<<"[ ";
while (current != nullptr) {
cout << current->data << " ";
current = current->next;
}
cout<<"]" << endl;
}
// void print_list() {
// node <T> *current = head;
// cout<<"[ ";
// while (current != nullptr) {
// cout << current->data << " ";
// current = current->next;
// }
// cout<<"]" << endl;
// }
// node<T>* find_value(T val) {
// node<T> *current = head;
// while (current != nullptr) {
// if (current->data == val) {
// return current;
// }
// else {
// current = current->next;
// }
// }
// return nullptr;
// }
// node<T>* find_index (unsigned int idx) {
// node<T> *current = head;
// for (int i = 0;; ++i, current = current->next) { //this (the last statement) is disgusting but written to prove a point.
// if (current == nullptr) {
// return nullptr;
// }
// if (i == idx) {
// return current;
// }
// }
// }
// bool swap_items (unsigned int index_a, unsigned int index_b) {
// node<T> *item1 = find_index(index_a);
// node<T> *item2 = find_index(index_b);
// if (item1 == nullptr || item2 == nullptr) {
// return false;
// }
// std::swap(item1->data, item2->data);
// return true;
// }
// bool remove_item (unsigned int idx) {
// node<T> *current = find_index(idx);
// if (current == head) {
// delete head;
// head = current->next;
// head->previous = nullptr;
// return true;
// }
// if (current == tail) {
// delete tail;
// tail = current->previous;
// tail->next = nullptr;
// return true;
// }
// if (current == nullptr) {
// return false;
// }
// node<T> *prev = current->previous;
// node<T> *nxt = current->next;
// prev->next = nxt;
// nxt->previous = prev;
// delete current;
// return true;
// }
// void move_front(T val) {
// node <T> *current = find_value(val);
// if (current == nullptr) {
// return;
// }
// if (current == head) {
// return;
// }
// if (current == tail) {
// current->next = head;
// head->previous = current;
// tail = current->previous;
// tail->next = nullptr;
// head = current;
// current->previous = nullptr;
// }
// else {
// node<T> *prev = current->previous;
// node<T> *nxt = current->next;
// prev->next = nxt;
// nxt->previous = prev;
// current->next = head;
// head->previous = current;
// head = current;
// current->previous = nullptr;
// }
// }
// void move_back(T val) {
// node<T> *current = find_value(val);
// if (current == nullptr) {
// return;
// }
// if (current == tail) {
// return;
// }
// if (current == head) {
// current->previous = tail;
// tail = head;
// head = current->next;
// head->previous = nullptr;
// current->next = nullptr;
// }
// else {
// node<T> *prev = current->previous;
// node<T> *nxt = current->next;
// prev->next = nxt;
// nxt->previous = prev;
// current->previous = tail;
// tail->next = current;
// tail = current;
// current->next = nullptr;
// }
// }
//};