lifo - Python: First In First Out Print -
i'm beginner in python , i'm having issue program:
the program below last in first out (lifo). want make 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) node in self.allnodes()) if self.head else 0 print('\u2510{}\u250c'.format(' '*length)) node in self.allnodes(): print('\u2502{:<{}}\u2502'.format(node.data, length)) print('\u2514{}\u2518'.format('\u2500'*length))
here 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: "rainbow" should @ bottom of "arc" or in fifo (pic below lifo)
i'm thinking put new def setprevious in nodelist dont know how. (to honest i'm new on these self.head = none stuffs . used write self.items = [])
any , tips appreciated! thank you!
apart learning purposes not advise using custom data structure making lifo or fifo. built in data-type list
fine after all.
you can add items using append
method , remove them using pop
. lifo this:
stack = list() stack.append(1) stack.append(2) stack.append(3) print stack.pop() #3 print stack.pop() #2 print stack.pop() #1
if supply integer argument pop
can specify element remove. fifo use index 0
first element:
stack = list() stack.append(1) stack.append(2) stack.append(3) print stack.pop(0) #1 print stack.pop(0) #2 print stack.pop(0) #3
Comments
Post a Comment