Skip to content

Commit

Permalink
fixeado operaciones delete y print
Browse files Browse the repository at this point in the history
  • Loading branch information
xhuniktzi committed Feb 21, 2021
1 parent df89e51 commit c3ee8c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
14 changes: 1 addition & 13 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
from models import ListaEnlazada

'''
TODO:
- fixear funciones 'delete' cuando se borra sobre una lista vacío
- fixear funcion 'print' cuando se imprime sobre vacío
'''

if __name__ == '__main__':
lista = ListaEnlazada()
lista.add_to_end('1')
lista.add_to_end('2')
lista.add_to_end('3')
lista.add_to_end('4')
lista.add_to_end('5')
lista.print_list()
pass
36 changes: 23 additions & 13 deletions src/models/ListaEnlazada.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,32 @@ def get_by_index(self, index: int):
node = node.next
return None

# Elimina el primer elemento de la lista
def delete_first(self):
self.head = self.head.next
if not self.is_void():
self.head = self.head.next

# Elimina el ultimo elemento de la lista
def delete_last(self):
node = self.head
prev = None
while node.next != None:
prev = node
node = node.next
prev.next = None
if not self.is_void():
node = self.head
prev = None
while node.next != None:
prev = node
node = node.next
if self.get_size() == 1:
self.head = None
else:
prev.next = None

# Imprimir Lista
def print_list(self):
print('head: {}'.format(self.head.data))
node = self.head
while node != None:
print('{}'.format(node.data), end=' -> ')
node = node.next
print()
if not self.is_void():
print('head: {}'.format(self.head.data))
node = self.head
while node != None:
print('{}'.format(node.data), end=' -> ')
node = node.next
print()
else:
print('is void')

0 comments on commit c3ee8c8

Please sign in to comment.