forked from JRositas/TC1031-SP-pt2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedList_2_1.h
66 lines (59 loc) · 1.59 KB
/
LinkedList_2_1.h
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
// Jose Rositas
// 30 Sept 2021
//Complejidad O(n) Lineal, depende de size
template <class T>
void LinkedList<T>::reverse(){
if(size>1){
Node<T> *curr = head->getNext();
Node<T> *aux = nullptr;
head->setNext(nullptr);
while(curr != nullptr){
aux = head;
head = curr;
curr = curr -> getNext();
head->setNext(aux);
}
}
}
//Complejidad O(n) Lineal, depende de size
template <class T>
void LinkedList<T>:: shift(int n){
if(size > 1){
int res = n % size;
if(res < 0){
res = size + res;
}
int saltos = res;
if(saltos > 0){
Node<T> *curr = head;
Node<T> *aux = nullptr;
for(int i=1; i<=saltos; i++){
aux = head;
head = head->getNext();
}
aux->setNext(nullptr);
aux = head;
while(aux->getNext() != nullptr){
aux = aux->getNext();
}
aux->setNext(curr);
}
}
}
//Complejidad O(n) Lineal, depende de size
template <class T>
bool LinkedList<T>::operator==(const LinkedList<T> &otra){
if(size == otra->size()){
Node<T> *curr1 = head;
Node<T> *curr2 = otra->head();
for (int i = 1; i <= size; i++)
{
if (curr1->getData() != curr2->getData()){
return false;
}
curr1 = curr1->getNext();
curr2 = curr2->getNext();
}
}
return true;
}