Description

Description:

Categories

Published

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.

Share

Transcript

Algorithm for Queue Implementation
Insert ( )
:
Description:
Here
QUEUE
is an array with
N
locations.
FRONT
and
REAR
points to the front and rear of
the
QUEUE
.
ITEM
is the value to be inserted.
1.
If (REAR == N) Then
[Check for overflow]
2.
Print: Overflow
3.
Else
4.
If (FRONT and REAR == 0) Then
[Check if QUEUE is empty]
(a) Set FRONT = 1
(b) Set REAR = 1
5.
Else
6.
Set REAR = REAR + 1
[Increment REAR by 1]
[End of Step 4 If]
7.
QUEUE[REAR] = ITEM
8.
Print: ITEM inserted [End of Step 1 If]
9.Exit
Delete ( )
:
Description:
Here
QUEUE
is an array with
N
locations.
FRONT
and
REAR
points to the front and rear of
the
QUEUE
.
1.
If (FRONT == 0) Then
[Check for underflow]
2. Print: Underflow 3. Else 4.ITEM = QUEUE[FRONT]
5.
If (FRONT == REAR) Then
[Check if only one element is left]
(a)
Set FRONT = 0 (b)
Set REAR = 0
6.
Else
7.
Set FRONT
= FRONT + 1
[Increment FRONT by 1]
[End of Step 5
If]
8.
Print: ITEM deleted [End of Step 1 If]
9.
Exit
Algorithm for Linked List
Insert an element in the single link list
1.
Begin
2.
Read the element into x
3.
Create an temp node in memory as follows
temp=(struct node *)size of (node)
4.
Set the values in temp node as follows
temp-> info =x
temp->next=null
5.
Search the element after which node will be inserted
current =SEARCH()
6.
insert temp node offer current node as follows
temp->next =current -> next
current->next=temp
7.
End.
Create :
1.
Begin
2.
Read the element into x
3.
Create a temp node in the memory temp =(struct node )sizeof (node)
4.
Assign the values in temp node as follows temp -> info =x
temp ->next=null
Algorithm for Infix to Postfix Conversion
Assumptions: Q - infix expression P - postfix expression 1. Push left parenthesis onto stack and add right parenthesis at the end of Q.
2. Scan Q from left to right and repeat step 3 to 6 for each element of Q until the STACK is empty.
3. If an operand is encountered add it to P.
4. If a left parenthesis is encountered push it onto the STACK.
5. If an operator is encountered, then
Repeatedly pop from STACK and add to P each operator
which has same precedence as or higher precedence than the operator
encountered.
Push the encountered operator onto the STACK.
6. If a right parenthesis is encountered, then
Repeatedly pop from the STACK and add to P each operator
until a left parenthesis is encountered.
Remove the left parenthesis; do not add it to P.
7. Exit
5.
check whether head is null or not if (head=null)
{
head=temp
current=temp
}
6.
else
{
current ->next =temp current ->current ->next
}
7.
follow step 1 to 4 to insert remaining element in the list.
8.
End.
DISPLAY :
1.
Begin
current=head
while (current != null)
2.
{
Print current -> info
3.
current =current ->next
4.
}
5.
End

We Need Your Support

Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks

SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...Sign Now!

We are very appreciated for your Prompt Action!

x