-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListaEmpleados.cpp
More file actions
executable file
·231 lines (175 loc) · 5.12 KB
/
ListaEmpleados.cpp
File metadata and controls
executable file
·231 lines (175 loc) · 5.12 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
// Created by Hugo.
#include "ListaEmpleados.h"
using namespace std;
ListaEmpleados::ListaEmpleados() {
if((header = new NodoEmpleados) == nullptr) //creando header
{
cout << "exception, constructor ListaEmpleados" << endl;
}
header->setPrev(header);
header->setNext(header);
}
ListaEmpleados::ListaEmpleados(ListaEmpleados &lista) {
copyAll(lista);
}
ListaEmpleados::~ListaEmpleados() {
deleteAll();
delete(header);
}
bool ListaEmpleados::isEmpty() {
return header->getNext() == header;
}
void ListaEmpleados::insertData(NodoEmpleados *prevNode, Empleado &emp) {
if(prevNode != nullptr and !isValidPos(prevNode))
{
cout<< "posicion invalida, intentando insertar lista Empleados" << endl;
}
NodoEmpleados* aux(nullptr);
aux = new NodoEmpleados(emp);
if(aux == nullptr) ///al parecer es unreachable code
{
cout << "Excepcion creando nodo, insert en lista Productoes" << endl;
}
if(prevNode == nullptr)
{
prevNode = header;
}
cout << "insert data Empleados.. " << aux->getData().toString() << endl;
aux->setPrev(prevNode);
aux->setNext(prevNode->getNext());
prevNode->getNext()->setPrev(aux);
prevNode->setNext(aux);
}
void ListaEmpleados::deleteData(NodoEmpleados *node) {
if(!isValidPos(node))
{
cout << "posicion invalida, intentando eliminar , lista Empleados" << endl;
}
node->getPrev()->setNext(node->getNext());
node->getNext()->setPrev(node->getPrev());
delete node;
}
void ListaEmpleados::deleteAll() {
NodoEmpleados* aux(nullptr);
while(header->getNext() != header)
{
aux = header->getNext();
header->setNext(aux->getNext());
delete aux;
}
header->setPrev(header);
}
bool ListaEmpleados::isValidPos(NodoEmpleados *node) {
NodoEmpleados* aux(header->getNext());
while(aux != header)
{
if(aux == node)
{
return true;
}
aux = aux->getNext();
}
return false;
}
void ListaEmpleados::copyAll(ListaEmpleados &lista) {
NodoEmpleados* aux(lista.header->getNext());
NodoEmpleados* newNode;
while (aux != lista.header)
{
if ((newNode = new NodoEmpleados(aux->getData())) == nullptr) {
cout << "excepcion, ListaEmpleados copyAll" << endl;
}
newNode->setPrev(header->getPrev());
newNode->setNext(header);
header->getPrev()->setNext(newNode);
header->setPrev(newNode);
aux = aux->getNext();
}
}
NodoEmpleados *ListaEmpleados::getFirstPos() {
if(isEmpty())
{
return nullptr;
}
return header->getNext();
}
NodoEmpleados *ListaEmpleados::getLastPos() {
if(isEmpty())
{
return nullptr;
}
return header->getPrev();
}
NodoEmpleados *ListaEmpleados::getPrevPos(NodoEmpleados *node) {
if(node == header->getNext() or !isValidPos(node))
{
return nullptr;
}
return node->getPrev();
}
NodoEmpleados *ListaEmpleados::getNextPos(NodoEmpleados *node) {
if(node == header->getPrev() or !isValidPos(node))
{
return nullptr;
}
return node->getNext();
}
NodoEmpleados *ListaEmpleados::findData(Empleado &emp) {
NodoEmpleados* aux(header->getNext());
while( aux != header)
{
if(aux->getData() == emp)
{
return aux;
}
aux = aux->getNext();
}
return nullptr;
}
Empleado &ListaEmpleados::retrieve(NodoEmpleados *node) {
if(!isValidPos(node))
{
cout << "excepcion, posicion invalida, intentando recuperar de lista de Productos" << endl;
}
return node->getData();
}
std::string ListaEmpleados::toString() {
NodoEmpleados* aux(header->getNext());
string result;
while (aux != header)
{
result += aux->getData().toString() + "\n\n";
aux = aux->getNext();
}
return result;
}
ListaEmpleados &ListaEmpleados::operator=(ListaEmpleados &list) {
deleteAll();
copyAll(list);
return *this;
}
void ListaEmpleados::write(const std::string &filename) {
/*
* Escritura con indices
* el archivo de indices se escribe con campos de longitud fija
* se escribe en indice el codigo del empleado
* se escribe en indice el lugar donde empieza el registro en el archivo de datos
* en el archivo de datos se escribe la informacion (cualquier metodo)
* ante Cualquier modificación, es necesario reescribir y recalcular el archivo de indices
* y el archivo de datos, por lo menos desde el registro modificado en adelante
* el indice se utiliza en el menu para poder acceder a los registros y modificarlos
* /// esta lista ya no es necesaria ///
* /// no es necesario cargar en la ram el archivo, con indices accedemos directamente a los datos
*
*/
}
void ListaEmpleados::read(const std::string &filename) {
/*
* Lectura de indices
* se busca secuencialmente en archivo indices el codigo
* y el espacio donde se encuentra el registro en el archivo de datos
* se ubica el puntero en ese punto del archivo de datos
* se lee el registro
* esta lista lee
*/
}