-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathLista.py
45 lines (37 loc) · 1.19 KB
/
Lista.py
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
class Nodo():
def __init__(self, dato):
self.__dato = dato
self.__siguiente = None
def getDato(self):
return self.__dato
def getSiguiente(self):
return self.__siguiente
def setDato(self, val):
self.__dato = val
def setSiguiente(self, val):
self.__siguiente = val
class Lista():
def __init__(self):
self.__cabecera = None
def agregarElemento(self,dato):
if (self.__cabecera != None):
puntero = self.__cabecera
while(puntero != None):
if(puntero.getSiguiente() == None):
puntero.setSiguiente(Nodo(dato))
break
puntero = puntero.getSiguiente()
else:
self.__cabecera = Nodo(dato)
def contarElementos(self):
if (self.__cabecera == None):
return 0
else:
contador = 1
puntero = self.__cabecera
while(puntero.getSiguiente() != None):
contador += 1
puntero = puntero.getSiguiente()
return contador
def getCabecera(self):
return self.__cabecera