2) QUEUE USING ARRAY:
1) Procedure ( VAL )
[Description]
Step 1: [Check Queue is overflow or not]
If REAR >= SIZE – 1
Then
Write (‘Overflow…..’)
Return
Step 2: [Check it is first element or not]
If FRONT = = -1
Then
FRONT 0
Step 3: [Increment REAR pointer by 1]
REAR REAR +1
Step 4: [Assign value]
Q [REAR] VAL
Step 5: [Finished]
Return
--------------------------------------------------------------------------------------------
2) Function DELETE ( )
[Description]
Step 1: [Check Queue is empty or not]
If FRONT < 0
Then
Write (‘Queue Underflow……’)
Return -1
Step 2: [Delete an element]
VAL Q [FRONT]
Step 3: [Queue Empty?]
If (FRONT = REAR)
Then
FRONT REAR -1
Else
FRONT FRONT +1
Step 4: [Return the Deleted element]
Return VAL
----------------------------------------------------------------------------------------------
3) Procedure PRINT
[Description]
Step 1: [Check Queue is empty or not]
If FRONT < 0
Then
Write (‘Underflow…..’)
Return
Step 2: [Print the element of Queue]
Repeat For I = FRONT, FRONT + 1 …While I < = REAR
Write Q [I]
Step 3: [Finished]
Return
3) QUEUE USING LINK LIST :
4) Procedure INSERT( VAL )
[Description]
Step 1: [Allocate the memory location]
NEWNODE NODE
Step 2: [Check memory is available or not]
If NEWNODE = NULL
Then
Write (‘Queue Overflow……)
Return
Step 3: [Insertion as a first NODE]
If REAR = NULL
Then
FRONT REAR NEWNODE
NEXT (REAR) NULL
Return
Step 4: [Insertion as other NODE]
NEXT (REAR) NEWNODE
REAR NEWNODE
NEXT (REAR) NULL
Return
--------------------------------------------------------------------------------------------
5) Function DELETE ( )
[Description]
Step 1: [Check Queue is empty or not]
If FRONT = NULL
Then
Write (‘Queue Underflow……’)
Return -1
Step 2: [Delete an element]
VAL INFO (FRONT)
Step 3: [If needed reseat pointer]
If FRONT = REAR
Then
FRONT REAR NULL
Else
FRONT NEXT (FRONT)
Step 4: [Return the Deleted element]
Return VAL
----------------------------------------------------------------------------------------------
6) Procedure PRINT
[Description]
Step 1: [Check Queue is empty or not]
If TEMP = NULL
Then
Write (‘Underflow…..’)
Return
Step 2: [Store FRONT into TEMP]
TEMP FRONT
Step 3: [Print the element of Queue]
Repeat While TEMP # NULL
Write INFO (TEMP)
TEMP NEXT (TEMP)
Step 4: [Finished]
Return
Sunday, 6 February 2011
Queue
11:53
vishal pandya
0 comments:
Post a Comment