-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTList.cpp
84 lines (72 loc) · 1.93 KB
/
TList.cpp
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
#include "TList.h"
#include "TTie.cpp"
#include <iostream>
///classe template da lista encadeada, usada somente para criar a pilha
template <typename T> TList<T>::TList(){
setHead(nullptr);
setTail(nullptr);
updateSize(0);
}
template <typename T> TList<T>::TList(TTie<T>* _head, TTie<T>* _tail){
setHead(_head);
setTail(_tail);
updateSize(0);
}
template <typename T> TTie<T>* TList<T>::getHead(){
return head;
}
template <typename T> TTie<T>* TList<T>::getTail(){
return tail;
}
template <typename T> int TList<T>::getSize(){
return Size;
}
template <typename T> void TList<T>::setHead(TTie<T>* newHead){
head = newHead;
}
template <typename T> void TList<T>::setTail(TTie<T>* newTail){
tail = newTail;
}
template <typename T> void TList<T>::updateSize(int newSize){
if(newSize == 0){
Size = 0;
}
Size = Size + newSize;
}
template <typename T> void TList<T>::setBegin(T &_info){
if(getSize() == 0){
TTie<T>* tie = new TTie<T>(_info, nullptr);
setHead(tie);
setTail(tie);
updateSize(1);
} else{
TTie<T>* newTie = new TTie<T>(_info, getHead());
setHead(newTie);
updateSize(1);
}
}
template <typename T> void TList<T>::removeBegin(){
if(getSize() == 0){
std::cout << "Erro!" << std::endl;
} else if(getSize() == 1){
delete getHead();
updateSize(-1);
} else{
TTie<T>* oldHead = getHead();
TTie<T>* newHead = oldHead->getNext();
setHead(newHead);
updateSize(-1);
delete oldHead;
}
}
template <typename T> void TList<T>::printList(){
if(getSize() == 0){
std::cout << "Lista Vazia!!" << std::endl;
} else {
TTie<T> *p = head;
while(p != nullptr){
std::cout << p->getInfo() << " ";
p = p->getNext();
}
}
}