How to resolve the algorithm Queue/Definition step by step in the ERRE programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Queue/Definition step by step in the ERRE programming language
Table of Contents
Problem Statement
Implement a FIFO queue. Elements are added at one side and popped from the other in the order of insertion.
Operations:
Errors:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Queue/Definition step by step in the ERRE programming language
Source code in the erre programming language
PROGRAM CLASS_DEMO
CLASS QUEUE
LOCAL SP
LOCAL DIM STACK[100]
FUNCTION ISEMPTY()
ISEMPTY=(SP=0)
END FUNCTION
PROCEDURE INIT
SP=0
END PROCEDURE
PROCEDURE POP(->XX)
XX=STACK[SP]
SP=SP-1
END PROCEDURE
PROCEDURE PUSH(XX)
SP=SP+1
STACK[SP]=XX
END PROCEDURE
END CLASS
NEW PILA:QUEUE
BEGIN
PILA_INIT ! constructor
FOR N=1 TO 4 DO ! push 4 numbers
PRINT("Push";N)
PILA_PUSH(N)
END FOR
FOR I=1 TO 5 DO ! pop 5 numbers
IF NOT PILA_ISEMPTY() THEN
PILA_POP(->N)
PRINT("Pop";N)
ELSE
PRINT("Queue is empty!")
END IF
END FOR
PRINT("* End *")
END PROGRAM
You may also check:How to resolve the algorithm Sorting algorithms/Shell sort step by step in the Maple programming language
You may also check:How to resolve the algorithm Integer sequence step by step in the C++ programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the Toka programming language
You may also check:How to resolve the algorithm Call an object method step by step in the Oforth programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the Asymptote programming language