Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. from tkinter import *
  2.  
  3.  
  4. class Node:
  5. def __init__(self, value=None, next=None):
  6. self.cargo = value
  7. self.next = next
  8.  
  9. def __str__(self):
  10. out = str(self.cargo)
  11. return out
  12.  
  13.  
  14. class List:
  15. def __init__(self):
  16. self.head = None
  17. self.end = None
  18. self.length = 0
  19.  
  20. def __str__(self):
  21. if self.head is not None:
  22. current = self.head
  23. out = 'List: [ ' + str(current.cargo) + ' '
  24. while current.next is not None:
  25. current = current.next
  26. out += str(current.cargo) + ' '
  27. return out + ']'
  28. else:
  29. out = 'List is clear'
  30. return out
  31.  
  32. def add(self, x):
  33. self.length += 1
  34. if self.head is None:
  35. self.end = self.head = Node(x, None)
  36. else:
  37. self.end.next = self.end = Node(x, None)
  38.  
  39. def clear(self):
  40. self.__init__()
  41.  
  42. def remove(self, i):
  43. if self.head is None:
  44. return
  45. curr = self.head
  46. count = 0
  47. if i == 0:
  48. self.head = self.head.next
  49. self.length -= 1
  50. return
  51. while curr is not None:
  52. if count == i:
  53. if curr.next is None:
  54. self.end = curr
  55. old.next = curr.next
  56. self.length -= 1
  57. break
  58. old = curr
  59. curr = curr.next
  60. count += 1
  61.  
  62. def search(self):
  63. while True:
  64. num = 0
  65. coun = 0
  66. curr = self.head
  67. deleted = False
  68. found = False
  69. for i in range(0, self.length):
  70. if curr.cargo % 4 == 0:
  71. found = True
  72. coun += 1
  73. num += coun
  74. coun = 0
  75. else:
  76. coun += 1
  77. curr = curr.next
  78. if found is True:
  79. self.remove(num-1)
  80. deleted = True
  81. if deleted is False:
  82. break
  83.  
  84.  
  85. L = List()
  86. root = Tk()
  87. root.title("Laba 1")
  88. root.geometry("640x360+0+0")
  89. root.resizable(False, False)
  90. text = Text(wrap=WORD)
  91. text.place(x=50, y=250, height=66, width=399)
  92. txt = Entry()
  93. txt.place(x=50, y=100, height=33, width=133)
  94.  
  95.  
  96. def new():
  97. s = txt.get()
  98. s = int(s)
  99. L.add(s)
  100. txt.delete(0, END)
  101.  
  102.  
  103. add = Button(root, text="Add", command=new)
  104. add.place(x=50, y=50, height=33, width=133)
  105.  
  106.  
  107. def output():
  108. text.delete(1.0, END)
  109. s = L.__str__()
  110. text.insert(1.0, s)
  111.  
  112.  
  113. def remove():
  114. L.search()
  115. if L.head is not None:
  116. add.config(state=DISABLED)
  117.  
  118.  
  119. show = Button(root, text="Print", command=output)
  120. show.place(x=200, y=100, height=33, width=133)
  121. replace = Button(root, text="Delete", command=remove)
  122. replace.place(x=200, y=50, height=33, width=133)
  123. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement