How to resolve the algorithm Queue/Usage step by step in the BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Queue/Usage step by step in the BASIC programming language

Table of Contents

Problem Statement

Create a queue data structure and demonstrate its operations. (For implementations of queues, see the FIFO task.)

Operations:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Queue/Usage step by step in the BASIC programming language

Source code in the basic programming language

      FIFOSIZE = 1000
      
      FOR n = 3 TO 5
        PRINT "Push ";n : PROCenqueue(n)
      NEXT
      PRINT "Pop " ; FNdequeue
      PRINT "Push 6" : PROCenqueue(6)
      REPEAT
        PRINT "Pop " ; FNdequeue
      UNTIL FNisempty
      PRINT "Pop " ; FNdequeue
      END
      
      DEF PROCenqueue(n) : LOCAL f%
      DEF FNdequeue : LOCAL f% : f% = 1
      DEF FNisempty : LOCAL f% : f% = 2
      PRIVATE fifo(), rptr%, wptr%
      DIM fifo(FIFOSIZE-1)
      CASE f% OF
        WHEN 0:
          wptr% = (wptr% + 1) MOD FIFOSIZE
          IF rptr% = wptr% ERROR 100, "Error: queue overflowed"
          fifo(wptr%) = n
        WHEN 1:
          IF rptr% = wptr% ERROR 101, "Error: queue empty"
          rptr% = (rptr% + 1) MOD FIFOSIZE
          = fifo(rptr%)
        WHEN 2:
          = (rptr% = wptr%)
      ENDCASE
      ENDPROC


  

You may also check:How to resolve the algorithm Josephus problem step by step in the Delphi programming language
You may also check:How to resolve the algorithm Anagrams step by step in the Wren programming language
You may also check:How to resolve the algorithm Doubly-linked list/Element insertion step by step in the D programming language
You may also check:How to resolve the algorithm Anagrams step by step in the Fortran programming language
You may also check:How to resolve the algorithm Deepcopy step by step in the Python programming language