Using array to execute the queue structure, Data Structure & Algorithms

Assignment Help:

Q. Using array to execute the queue structure, write down an algorithm/program to

(i) Insert an element in the queue.

(ii) Delete an element from the queue.                                                        

 

Ans.

(i) Algorithm to Insert an element in the given queue.

QINSERT( QUEUE, N, FRONT, REAR, ITEM)

This method inserts an elements ITEM into a queue.

1. [QUEUE already filled ?]

if FRONT =1 and REAR =N or if FRONT = REAR +1 then

write:OVERFLOW, and Return.

2. [Find new value of REAR]

If FRONT : = NULL, then : [QUEUE initially empty]

Set FRONT : = 1 and REAR : = 1, Else if REAR = N then;

Set REAR : = 1

Else:

Set REAR : = REAR + 1 [End of if structure]

3.Set QUEUE [REAR]: = ITEM [This inserts new elements]

4. Return

(ii) Algorithm to erase an element from the Queue

QDELETE (QUEUE, N, FRONT, REAR, ITEM)

This method deletes an element from a Queue and assign it to the variable ITEM.

1.  [Queue already Empty?]

If  FRONT:= NULL, then write UNDERFLOW and Return

2.  Set ITEM:=QUEUE[FRONT]

3.  [Find new value of FRONT]

If FRONT=REAR, THEN[Queue has only one element to start.]

Set FRONT:=NULL and REAR:=NULL Else  if      FRONT=N then:

Set FRONT:=1

Else:

Set FRONT:=FRONT+1 [End of If structure]

4.  Return.


Related Discussions:- Using array to execute the queue structure

Conversion of general trees into the binary trees, By taking an appropriate...

By taking an appropriate example explain how a general tree can be represented as a Binary Tree.                                                                    C onversio

What is a spanning tree of a graph, What is a Spanning tree of a graph? ...

What is a Spanning tree of a graph? A Spanning Tree is any tree having of vertices of graph tree and some edges of graph is known as a spanning tree.

Darw a flowchart to input 3 numbers, This algorithm inputs 3 numbers, every...

This algorithm inputs 3 numbers, every number goes through successive division by 10 until its value is less than 1. An output is produced which comprise the number input and a val

Which sorting algorithm is adaptable to singly linked list, Which sorting a...

Which sorting algorithm is easily adaptable to singly linked lists? Simple Insertion sor t is easily adabtable to singly linked list.

What is binary space partition, Binary Space Partition A binary space-p...

Binary Space Partition A binary space-partitioning (BSP) tree is an efficient method for determining object visibility by painting surfaces onto the screen from back to front,

COBOL, write a COBOL program to find the biggest of two numbers

write a COBOL program to find the biggest of two numbers

Algorithm, implement multiple stacks in a single dimensional array. write a...

implement multiple stacks in a single dimensional array. write algorithm for various stack operation for them

Perform breadth -first search, You are given two jugs, a 4-gallon one and a...

You are given two jugs, a 4-gallon one and a 3-gallon one. Neither has any measuring marker on it. There is a tap that can be used to fill the jugs with water. How can you get exac

Number of leaf nodes in a complete binary tree, The number of leaf nodes in...

The number of leaf nodes in a complete binary tree of depth d is    2 d

State in brief about assertion, State  in brief about assertion Asser...

State  in brief about assertion Assertion: A statement which should be true at a designated point in a program.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd