FIFO Page replacement Algorithm in Python


FIFO Page Replacement Algorithm in Python


FIFO is an acronym for First in First Out in the case of an operating system. The concept is a page replacement technique used to switch data to and from and the main memory. The technique replaces the page from the queue which was first inserted. The operating system uses this concept to switch memory chunks, also known as the pages from the secondary memory to the main memory.

The approach is implemented in every operating system with the help of an algorithm. Such an algorithm is known as the scheduling algorithm and is used to assign processing time to every process which is in the waiting state.

Program in Python

#Python programming code to implement a FIFO algorithm.

from NodeList import Node

class PrepInsta:

    def __init__(s):

    s.head = None

#code to define the Queue 

   def enqueueQLL(s,item):

   temp = Node(str(item))

#assigning node to the temproary variable 


   s.nodehead = temp

#assigning data to the node 

  qlength = max(len( for node in s.allNodes()) if s.head else 0

  print('\u2510{}\u250c'.format(' '*length))

  for node in s.allNodes():

     print('\u2502{:<{}}\u2502'.format(, length))


#class defining NodeList
#driver code

class PrepInstaNode:

#code to initialize data 
    def __init__(s,initdata): = initdata = None
#code to input data 

    def getData(sf):

#code to set pointer 
    def getNext(s):


#code to assign data 

    def setData(s,new): = new
#code to assign pointer 
    def setNext(s,newnext): = newnext

Output –

q = QueueLL()



The queue will contain elements: