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

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.

Algorithms and flowcharts, write an algorithm and draw a flowchart to calcu...

write an algorithm and draw a flowchart to calculate the perimeter and area of a circle

What is assertions and abstract data types, Assertions and Abstract Data Ty...

Assertions and Abstract Data Types Even though we have defined assertions in terms of programs, notion can be extended to abstract data types (which are mathematical entities).

Explain division method, Explain Division Method Division Method: - In...

Explain Division Method Division Method: - In this method, key K to be mapped into single of the m states in the hash table is divided by m and the remainder of this division

Determine the warnock algorithm, Warnock's Algorithm A divide and conqu...

Warnock's Algorithm A divide and conquer algorithm Warnock (PolyList PL, ViewPort VP) If (PL simple in VP) then Draw PL in VP, else Split VP vertically and horiz

Convertion, how we can convert a graph into tree

how we can convert a graph into tree

Pseudocode algorithm to print the numbers from 1 to 10, 1. Write a pseudoco...

1. Write a pseudocode algorithm to print the numbers from 1 to 10, and then from 10 to 1, using exactly one loop. 2. The function contains() takes a food as an argument and tell

Data Structure, Ask consider the file name cars.text each line in the file ...

Ask consider the file name cars.text each line in the file contains information about a car ( year,company,manufacture,model name,type) 1-read the file 2-add each car which is repr

Program for binary search, Illustrates the program for Binary Search. P...

Illustrates the program for Binary Search. Program: Binary Search /*Header Files*/ #include #include /*Functions*/ void binary_search(int array[ ], int value,

Addressing modes, Compare zero-address, one-address, two-address, and three...

Compare zero-address, one-address, two-address, and three-address machines by writing programs to compute: Y = (A – B X C) / (D + E X F) for each of the four machines. The inst

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