Skip to content

Instantly share code, notes, and snippets.

@Florencia-97
Created October 29, 2016 20:53
Show Gist options
  • Save Florencia-97/1dd704bfe9de0751325e5c978208d065 to your computer and use it in GitHub Desktop.
Save Florencia-97/1dd704bfe9de0751325e5c978208d065 to your computer and use it in GitHub Desktop.
class _Nodo:
def __init__(self,dato,prox=None,ant=None):
self.dato=dato
self.prox=prox
self.ant=ant
class ListaDoble:
def __init__(self):
self.prim=None
self.len=0
def append (self,dato):
if self.len==0:
self.prim=_Nodo(dato)
else:
nodo=self.prim
while nodo.prox!= None:
nodo=nodo.prox
nodo.prox=_Nodo(dato)
def insert(self,dato,pos):
if pos==self.len:
self.append(dato)
else:
nodo=nodo.prim
for i in range (pos-1):
nodo=nodo.prox
anterior=nodo
prox=nodo.prox
nuevo_nodo=_Nodo(dato,prox,anterior)
nodo.prox=nuevo_nodo
prox.ant=nuevo_nodo
def pop (self,pos):
nodo =self.prim ##tengo que devolver el texto
if pos==0:
dato=nodo.dato
nodo_nuevo_1=nodo.prox
nodo_nuevo_1.ant=None
self.prim=nodo_1
elif pos==self.len:
while nodo.prox!=None:
nodo=nodo.prox
dato=nodo.dato
nodo_ant=nodo.ant
nodo_ant.prox=None
else:
for i in range(pos-1):
nodo=nodo.prox
dato=nodo.prox.dato
prox=nodo.prox.prox
prox.ant=nodo
nodo.prox=prox
return dato
def remove(self,texto):
nodo=self.prim
if nodo.dato==texto:
nodo_seg=nodo.prox
nodo_seg.ant=None
self.prim=nodo_seg
else:
while nodo != None:
if nodo.dato.lower()==texto.lower(): #revisar!!
nodo_ant=nodo.ant
nodo_prox=nodo.prox
nodo_prox.ant=nodo_ant
nodo_ant.prox=nodo_prox
nodo=nodo.prox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment