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

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.

Posted Date: 7/13/2012 1:24:12 AM | Location : United States







Related Discussions:- Using array to execute the queue structure, Assignment Help, Ask Question on Using array to execute the queue structure, Get Answer, Expert's Help, Using array to execute the queue structure Discussions

Write discussion on Using array to execute the queue structure
Your posts are moderated
Related Questions
Link list representation of a circular queue is more efficient as it employs space more competently, of course with the added cost of storing the pointers. Program 7 gives the link

Write an algorithm in form of a flowchart that takes temperatures input over a 100 day period (once per day) and outputs the number of days when temperature was below 20C and numbe

An unsorted array is searched through linear search that scans the array elements one by one until the wanted element is found. The cause for sorting an array is that we search

Implement multiple queues in a single dimensional array. Write algorithms for various queue operations for them.

MID SQUARE METHOD

Illustrate the Back Face Detection Method A single polyhedron is a convex solid, which has no external angle between faces less  than 180° and there is a simple object space me

1. Use the Weierstrass condition, find the (Strongly) minimizing curve and the value of J min for the cases where x(1) = 0, x(2) = 3. 2. The system = x 1 + 2u; where

Implementing abstract data types A course in data structures and algorithms is hence a course in implementing abstract data types. It may seem that we are paying a lot of atten

Define Wire-frame Model This skeletal view is called a Wire-frame Model. Although not a realistic representation  of the object, it is still very useful in the early stages of

Determine the class invariants- Ruby Ruby has many predefined exceptions classes (like ArgumentError) and new ones can be created easily by sub-classing StandardError, so it's