Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Node: #узел
- def __init__(self, data, prev, nexT):
- self.data = data
- self.prev = prev
- self.nexT = nexT
- class Book:
- def __init__(self, name_book = ' ', name_autor = ' ', number_page = ' ', year_publish = ' ', publisher = ' '):
- print("Enter name book : ")
- self.name_book = input()
- print("Enter name autor : ")
- self.name_autor = input()
- print("Enter number page : ")
- self.number_page = int(input())
- print("Enter year publish : ")
- self.year_publish = input()
- print("Enter name publisher : ")
- self.publisher = input()
- class Double_Linked_List:
- def __init__(self):
- self.head = None # начало списка (голова)
- self.tail = None # хвост списка
- def add_node(self):
- data = Book()
- new_node = Node(data, None, None)
- if self.head is None:
- self.head = self.tail = new_node
- else:
- new_node.prev = self.tail
- new_node.next = None
- self.tail.next = new_node
- self.tail = new_node
- def show(self):
- if self.head is None:
- print(None)
- else:
- current_node = self.head
- while current_node is not None:
- if current_node.nexT is None:
- print(current_node.data.name_book, end=" ")
- print(current_node.data.name_autor, end=" ")
- print(current_node.data.number_page, end=" ")
- print(current_node.data.year_publish, end=" ")
- print(current_node.data.publisher, end=" ")
- print()
- break
- else: # чет не понимаю что это? Это тип, если уже дошло до конца, вывести "----" ?
- print(current_node.data, end=" <---> ")
- current_node = current_node.nexT
- def find(self, name_find):
- count = self.head
- while count is not None:
- if count.nexT is None:
- if count.data.name_autor == name_find:
- print(count.data.name_book, end=" ")
- print(count.data.name_autor, end=" ")
- print(count.data.number_page, end=" ")
- print(count.data.year_publish, end=" ")
- print(count.data.publisher, end=" ")
- break
- else:
- print("Not book this autor ")
- break
- d1 = Double_Linked_List()
- d1.add_node()
- d1.show()
- print("Enter finde autor : " )
- f = input()
- d1.find(f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement