Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. class Node:
  2. def __init__(self, value):
  3. self.next = None
  4. self.value = value
  5.  
  6. class List:
  7. def __init__(self, value):
  8. self.head = Node(value)
  9.  
  10. def insert(self, value):
  11. current = self.head
  12. while current.next is not None:
  13. current = current.next
  14. current.next = Node(value)
  15.  
  16. def find(self, value):
  17. current = self.head
  18. while current is not None:
  19. if current.value == value:
  20. return True
  21. else:
  22. current = current.next
  23. return False
  24.  
  25. def delete(self, value):
  26. if self.find(value) is not True:
  27. return "Not in list"
  28. else:
  29. current = self.head
  30. while current is not None:
  31. if current.next.value == value:
  32. current.next = current.next.next
  33. break
  34. else:
  35. current = current.next
  36.  
  37. def print(self):
  38. current = self.head
  39. while current is not None:
  40. if current.value is not None:
  41. print(current.value)
  42. current = current.next
  43.  
  44. v = List(None)
  45.  
  46. v.insert(10)
  47. v.insert(20)
  48. v.insert(30)
  49. v.print()
  50. print('---')
  51. v.delete(20)
  52. v.print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement