I'm a beginner in python and I'm having an issue with this program:
The program below is a Last In First Out (LIFO). I want to make it 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" should be at the bottom of "Arc" or in FIFO (pic below is LIFO)
I'm thinking to put a new def like setPrevious in the NodeList But I dont know how. (to be honest I'm really new on these self.head = none stuffs . I used to write self.items = [])
Any help and tips will be appreciated! Thank you!