Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. class Node: #узел
  2. def __init__(self, data, prev, nexT):
  3. self.data = data
  4. self.prev = prev
  5. self.nexT = nexT
  6.  
  7. class Book:
  8. def __init__(self, name_book = ' ', name_autor = ' ', number_page = ' ', year_publish = ' ', publisher = ' '):
  9. print("Enter name book : ")
  10. self.name_book = input()
  11. print("Enter name autor : ")
  12. self.name_autor = input()
  13. print("Enter number page : ")
  14. self.number_page = int(input())
  15. print("Enter year publish : ")
  16. self.year_publish = input()
  17. print("Enter name publisher : ")
  18. self.publisher = input()
  19.  
  20. class Double_Linked_List:
  21.  
  22. def __init__(self):
  23. self.head = None # начало списка (голова)
  24. self.tail = None # хвост списка
  25.  
  26. def add_node(self):
  27. data = Book()
  28. new_node = Node(data, None, None)
  29. if self.head is None:
  30. self.head = self.tail = new_node
  31. else:
  32. new_node.prev = self.tail
  33. new_node.next = None
  34. self.tail.next = new_node
  35. self.tail = new_node
  36.  
  37. def show(self):
  38. if self.head is None:
  39. print(None)
  40. else:
  41. current_node = self.head
  42. while current_node is not None:
  43. if current_node.nexT is None:
  44. print(current_node.data.name_book, end=" ")
  45. print(current_node.data.name_autor, end=" ")
  46. print(current_node.data.number_page, end=" ")
  47. print(current_node.data.year_publish, end=" ")
  48. print(current_node.data.publisher, end=" ")
  49. print()
  50. break
  51. else: # чет не понимаю что это? Это тип, если уже дошло до конца, вывести "----" ?
  52. print(current_node.data, end=" <---> ")
  53. current_node = current_node.nexT
  54.  
  55. def find(self, name_find):
  56. count = self.head
  57. while count is not None:
  58. if count.nexT is None:
  59. if count.data.name_autor == name_find:
  60. print(count.data.name_book, end=" ")
  61. print(count.data.name_autor, end=" ")
  62. print(count.data.number_page, end=" ")
  63. print(count.data.year_publish, end=" ")
  64. print(count.data.publisher, end=" ")
  65. break
  66. else:
  67. print("Not book this autor ")
  68. break
  69.  
  70. d1 = Double_Linked_List()
  71. d1.add_node()
  72. d1.show()
  73. print("Enter finde autor : " )
  74. f = input()
  75. d1.find(f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement