I am starting to work on python and I have a problem with this program:
The program below is Last In First Out (LIFO). I want to make a First in First Out (FIFO) program.
from NodeList import Node
class QueueLL:
def __init__(self):
self.head = None
def enqueueQLL(self,item):
temp = Node(str(item))
temp.setNext(self.head)
self.head = temp
length = max(len(node.data) for node in self.allNodes()) if self.head else 0
print('\u2510{}\u250c'.format(' '*length))
for node in self.allNodes():
print('\u2502{:<{}}\u2502'.format(node.data, length))
print('\u2514{}\u2518'.format('\u2500'*length))
Here is the NodeList:
class Node:
def __init__(self,initdata):
self.data = initdata
self.next = None
def getData(self):
return self.data
def getNext(self):
return self.next
def setData(self,newdata):
self.data = newdata
def setNext(self,newnext):
self.next = newnext
NOTE: The “rainbow” must be at the bottom of the “arc” or in the FIFO (Figure below LIFO)

I am thinking of adding a new def, like setPrevious to a NodeList. But I do not know how to do this. (to be honest, I'm really new to these self.head = none stuffs. I used to write self.items = [])
Any help and advice would be appreciated! Thanks!
source
share