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
Q. Explain w hat are the stacks? How can we use the stacks  to check whether an expression is correctly parentheses or not. For example (()) is well formed but (() or )()( is not w

How does cpu''s part tming and controls generate and controls signls in computer?

i want to write code for unification algorithm with for pattern matching between two expression with out representing an expression as alist

Find a minimum cost spanning arborescence rooted at r for the digraph shown below, using the final algorithm shown in class. Please show your work, and also give a final diagram wh

How do I submit a three page assignment

What is the best case complexity of quick sort In the best case complexity, the pivot is in the middle.

Define the terms     i) Key attribute     ii) Value set  Key attribute:  An entity  type  usually  has  an attribute  whose  values  are  distinct  fr

Worst Case: For running time, Worst case running time is an upper bound with any input. This guarantees that, irrespective of the type of input, the algorithm will not take any lo

Search engines employ software robots to survey the Web & build their databases. Web documents retrieved & indexed through keywords. While you enter a query at search engine websit

Merging two sequence using CREW merge