loading
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Node:
  def __init__(self, data, nextNode):
    self.data = data
    self.nextNode = nextNode
  
  def getData(self):
    return self.data
  
  def getNextNode(self):
    return self.nextNode
  
  def setData(self, data):
    self.data = data
  
  def setNextNode(self, nextNode):
    self.nextNode = nextNode

class linkedList:
  def __init__(self):
    self.headNode = None
    self.tailNode = self.headNode

  def getHead(self):
    return self.headNode
  
  def addNode(self, data):
    if not self.headNode:
      self.headNode = Node(data, None)
      self.tailNode = self.headNode
      return
    node = Node(data, None)
    self.tailNode.setNextNode(node)
    self.tailNode = self.tailNode.getNextNode()
  
  def printList(self):
    tempNode = self.getHead()
    while tempNode != None:
      print(tempNode.getData())
      tempNode = tempNode.getNextNode()
  

myList = linkedList()

myList.addNode(15)
myList.printList()
print()

myList.addNode(55)
myList.printList()
print()

myList.addNode(175)
myList.printList()