0% found this document useful (0 votes)
8 views

Module 2

Maths..

Uploaded by

pirati.yaswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Module 2

Maths..

Uploaded by

pirati.yaswanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Module-2

Concept of Array, Stack, Queue & Linked List


**********************************************************

Array :
It is a linear data structure where the elements will store and process in a sequential
manner.

 The first location of the array is called as Lower Bound of the Array.
 The last location of the array is called as Upper Bound of the Array.
 The Address of the first location of the Array is called as Base address of the
Array.
Overflow condition
If the structure is full of elements, and after that if we will try to insert an element
into the structure, then such condition is called as overflow condition.
Underflow condition
If the structure is totally empty, and after that if we will try to delete an element from
the structure, then such condition is called as underflow condition.
Stack
It is a linear array where both the insertion and deletion operation will be performed
at a single end i.e. called as TOP end of the stack.
Top: It is a pointer which points to the location of top element in the Stack.
Max_Stack: It is a pointer which points the size of the Stack.
In Stack, mainly there are two operations can be performed named as Push and Pop
operation
The insertion operation into the stack is called as PUSH operation. Similarly, the
deletion operation from the stack is called as POP operation.
Though in stack both insertion and deletion operation performed at one end only,
hence we can say the Stack follows LIFO (Last In First Out) procedure in memory.

Prepared By: Dr. Radha Mohan Pattanayak 1


MaxStack 7 .

6 .

Top 5 9

4 7

3 5

2 3

1 2

Index Element

Structure of a STACK

Top 7 4 MaxStack MaxStack 7

6 1 6

5 9 5

4 7 4

3 5 3

2 3 2

1 2 1

Index Element Top 0

Overflow Condition of a STACK Underflowflow Condition of a


STACK
Overflow: Top = MaxStack Underflow: Top = 0
Algorithm for Push Operation
Push (Stack, item, top, MAXStack)
S1: Input : item
S2: if (top = MAXStack), then
Print : ‘Overflow’
return
[end of if ]
S3: set top := top+1
S4: set Stack[top] := item
S5: exit
Algorithm for Pop Operation
Pop (Stack, item, top)

Prepared By: Dr. Radha Mohan Pattanayak 2


S1: if(top=0), then
Print : ‘UNDERFLOW’
Return
[ end of if ]
S2: set item:=Stack[top]
Set top:=top-1
S3: exit
Application of Stack
In our day-to-day life the concept of Stack is implemented in various places
such as….
1) To convert an Infix expression to it’s equivalent Postfix expression.
2) To evaluate a Postfix expression.
3) To traverse a Graph by using DFS procedure etc..
Infix Expression:
In an expression if the operator symbol will use in between two operands then that
expression is called as Infix expression. e.g. A + B
Prefix Expression:
In an expression if the operator symbol will use before the operands then that expression
is called as Prefix expression. e.g. + A B
Postfix Expression:
In an expression if the operator symbol will use after the operands then that expression is
called as Postfix expression. e.g. A B +
Procedure to convert an Infix expression to Postfix expression using STACK
S1: Add “(” at the beginning and “)” at the end of the infix Expression
S2: If an operand will encounter, then add that operand into postfix expression
S3: If an operator will encounter, then compare the priority of the infix operator with the
Stack operator
(a) If the infix operator is a lower priority operator then, pop all the higher and equal
priority operators from stack and add to them into postfix expression and then
push the infix operator into the stack.
(b) If the stack operator is a lower priority operator then, simply push the infix
operator into the stack.
(c) If there is no stack operator then, simply push the infix operator into the stack.
S4: If a “(” will encounter then push it into the stack
If a “)” will encounter, pop all the operators from the stack until a “(” will encounter in
S5:
the stack, and then add all the operators into the postfix expression.
S6: Continue Step 2 to Step 5 until Stack is not empty.
Question:
Convert the following infix expression into postfix expression:

Prepared By: Dr. Radha Mohan Pattanayak 3


A+B^(C+D)-E*F+G
Infix Symbol Operator Stack Postfix Symbol

( (

A ( A
+ (+ A
B (+ AB
^ (+^ AB
( (+^( AB
C (+^( ABC
+ (+^(+ ABC
D (+^(+ ABCD
) (+^ ABCD+
- (- ABCD+^+
E (- ABCD+^+E
* (-* ABCD+^+E
F (-* ABCD+^+EF
+ (+ ABCD+^+EF*-
G (+ ABCD+^+EF*-G
) Empty ABCD+^+EF*-G+
Procedure to evaluate to a Postfix expression using STACK

S1: If an operand will encounter, then push it into the stack

S2: If an operator ℗ will encounter then,


(a) Pop two elements (i.e. operands) from the stack

(b) Perform an operation using the two popped operands with the operator ℗
Result = Top2 ℗ Top1
(c) Push the result of the operation again into the stack

S3: Continue Step 1 and Step 2 for each element in the postfix expression

S4: Res = Stack [top]


Question:
Explain the procedure to evaluate postfix expression. 7 3 4 + - 2 4 5 / + * 6 / 7 +
Prepared By: Dr. Radha Mohan Pattanayak 4
Concept of Linked List
***********************

 It is a linear type data structure which is the dynamic collection of blocks in the
memory where generally an element will store into it.
 Each and every block in the Linked List is known as node.
 Every node has divided into two parts named as
a) Information part
b) Linked part or Address part
 Information part of a node generally holds the element in the memory.
 Linked part or Address part of a node generally holds the address of the next
node in the list.
 In linked list there is a pointer named as Start or Head which will hold the address
of the first node in the list.
 In the linked list the link part of last node will contain NULL value, which
represents there is no node present after this node.
Types of Linked List
Linked list is divided into 3 types such as:
a) Single Linked List
b) Double Linked List
c) Circular Linked List
Single Linked List
The list where each and every node of the list is divided into two parts, then such
type of list structure is called as Single Linked List.

Prepared By: Dr. Radha Mohan Pattanayak 5


Start

30 7 40 4 50 9 60

5 7 4 9

Procedure to create a node:


class Node
{
int info;
Node link;
Node( int item)
{
info = item;
link = null;
}
}
Node newnode = new Node () ;
Algorithm to insert an element at First position into the Linked List

Finsert ( List, Item, start, info, newnode )


S1: Set newnode . info := item
Set newnode . link := null
S2: if ( start = null ), then
set start : = newnode
else
set newnode . link := start
set start := newnode
[ End of if-else ]
S3: End

Algorithm to insert an element at Last position into the Linked List

Linsert (List, Item, start, info, newnode)


S1: Set newnode . info := item
Set newnode . link := null

Prepared By: Dr. Radha Mohan Pattanayak 6


S2: if ( start = null ), then
Set start : = newnode
else
Set ptr := start
[ End of if-else ]
S3: Repeat step 3 while (ptr.link != null)
Set ptr := ptr . link
[ End of while loop ]
S4: Set ptr . link := newnode
S5: End

Algorithm to insert an element at any position in the linked list

Posinsert ( List, Item, start, info, link, newnode, pos )


S1: Set newnode . info := item
Set newnode . link := null
S2: if ( start = null ), then
Set start : = newnode
else
Set ptr := start
Set c := 1
[ End of if-else ]
S3: Repeat step 3 while ( c < pos-1 )
Set ptr := ptr . link
[ End of while loop ]
S4: Set newnode . link := ptr . link
Set ptr . link := newnode
S5: End

Algorithm to delete an element from First position in the linked list

Fdelete ( List, start, link )


S1: if ( start = null ), then
print: ‘UNDERFLOW’
return

Prepared By: Dr. Radha Mohan Pattanayak 7


else if (start . link = null), then
Set start := null
else
Set start := start . link
[ End of if-else ]
S2: End

Algorithm to delete an element from Last position in the linked list

Ldelete ( List, start, link )


S1: if ( start = null ), then
print: ‘UNDERFLOW’
return
else if (start . link = null), then
Set start := null
else
Set ptr1 := null
Set ptr2 := start
[ End of if-else ]
S2: Repeat step 2 while ( ptr2 . link != null )
Set ptr1 := ptr2
Set ptr2 := ptr2 . link
[ End of while ]
S3: Set ptr1 . link := null
S4: End

Algorithm to delete an element from any position in the linked list

Pdelete ( List, start, link, pos )


S1: Set c := 1
Set ptr1 := null
Set ptr2 := start
S2: Repeat step 2 while ( c < pos )
if ( ptr2 . link = null ), then
Print: ‘Sufficient nodes aren't present’

Prepared By: Dr. Radha Mohan Pattanayak 8


return
else
Set ptr1 := ptr2
Set ptr2 := ptr2 . link
[ End of if-else ]
[ End of while ]
S3: Set ptr1 . link := ptr2 . link
Set ptr2 . link := null
S4: End

Double Linked List


The linked list where each and every node of the list is divided into three parts is
called as a Double linked list.

1 7 5 2 9 7 3 6 9 4

5 7 9 6
Every node has divided into three parts named as
 Left Link part or Left Address part
 Information part
 Right Link part or Right Address part

LLink or Information RLink or


Address Part Part Address Part

 The LLink part of a node will store the address of it’s previous node present in
the linked list.
 The information part of a node will store the element inside the memory.
 The RLink part of a node will store the address of it’s next node present in the
linked list.
 In the Double linked list the Rlink part of last node as well as will the Llink part
of first node contain NULL value, which represents there is no node present
after and before of the present node.

Procedure to create a node in Double linked list


Prepared By: Dr. Radha Mohan Pattanayak 9
class Node
{
Node llink;
int info;
Node rlink;
Node( int item)
{
llink = null ;
info = item;
rlink = null;
}
}

Algorithm to insert an element at First position in the Double linked list

Finsert ( List, Item, start, info, link, newnode )


S1: Set newnode . llink := null
Set newnode . info := item
Set newnode . rlink := null
S2: if ( start = null ), then
Set start : = newnode
return
[ End of if ]
S3: Set newnode . rlink := start
Set start . llink := newnode
Set start := newnode
S5: End

Algorithm to insert an element at Last position in the Double linked list

Linsert ( List, Item, start, info, llink, rlink, newnode )


S1: Set newnode . llink := null
Set newnode . info := item
Set newnode . rlink := null
S2: if ( start = null ), then

Set start : = newnode

Prepared By: Dr. Radha Mohan Pattanayak 10


else
Set ptr := start
[ End of if-else ]
S3: Repeat step 3 while ( ptr . rlink != null )
Set ptr := ptr . rlink
[ End of while loop ]
S4: Set newnode . llink := ptr
Set ptr . rlink := newnode
S5: End

Algorithm to insert an element at any position in the Double linked list

Pinsert ( List, Item, start, info, llink, rlink, newnode, pos )


S1: Set newnode . llink := null
Set newnode . info := item
Set newnode . rlink := null
Set ptr := start
Set c := 1
S2: Repeat step 2 while ( c < pos - 1)
if ( ptr . link = null )
Print: ’ Sufficient nodes aren't present’
return
else
Set ptr := ptr . rlink
[ End of if-else ]
[ End of while loop ]
S3: Set newnode . rlink := ptr . rlink
Set newnode . llink := ptr
Set ptr . rlink := newnode
S5: End

Algorithm to delete an element from First position in the Double


linked list

Fdelete ( List, Item, start, llink, rlink )


S1: if ( start = null ), then

Prepared By: Dr. Radha Mohan Pattanayak 11


print: ‘UNDERFLOW’
return
[ End of if ]
S2: if (start . rlink = null), then
Set start := null
return
[ End of if ]
S3: Set ptr := start
Set item := start . info
Set start := start . rlink
Set start . llink := null
Set ptr . rlink := null
S4: End

Algorithm to delete an element from Last position in the Double linked list

Ldelete ( List, Item, start, llink, rlink )


S1: if ( start = null ), then
print: ‘UNDERFLOW’
return
[ End of if ]
S2: if (start . rlink = null), then
Set start := null
return
[ End of if ]
S3: Set ptr1 := null
Set ptr2 := start
S4: Repeat step 4 while ( ptr2 . rlink != null )
Set ptr1 := ptr2
Set ptr2 := ptr2 . rlink
[ End of while loop ]
S5: Set ptr2 . llink := null
Set ptr1 . rlink := null
S6: End

Prepared By: Dr. Radha Mohan Pattanayak 12


Algorithm to delete an element from any position in the Double linked list

Pdelete ( List, Item, start, llink, rlink, pos )


S1: Set c := 1
Set ptr1 := null
Set ptr2 := start
Set ptr3 := null
S2: Repeat step 2 while ( c < pos )
if ( ptr2 . rlink = null ), then
Print: ‘Sufficient nodes aren't present’
return
else
Set ptr1 := ptr2
Set ptr2 := ptr2 . rlink
[ End of if-else ]
[ End of while ]
S3: Set ptr3 := ptr2 . rlink
Set ptr1 . rlink := ptr2 . rlink
Set ptr3 . llink := ptr1
Set ptr2 . rlink := null
Set ptr2 . llink := null
S4: End

Circular Linked List


 The linked list where the link part of the last node will point to the first node of
the list, then such type of list is called as Circular linked list.
 In Circular linked list the first node of the list is pointed by both start pointer as
well as the link part of the last node in the list.

Prepared By: Dr. Radha Mohan Pattanayak 13


Start

30 7 40 4 50 9 20 5

5 7 4 9

Algorithm to insert an element at First position in the Circular linked list

Finsert ( List, Item, start, info, link, newnode )


S1: Set newnode . info := item
Set newnode . link := null
S2: if ( start = null ), then
Set start : = newnode
Set newnode . link : = start
else
Set ptr := start
[ End of if-else ]
S3: Repeat step 3 while ( ptr . link != start )
Set ptr := ptr . link
[ End of while loop ]
S4: Set newnode . link := start
Set start := newnode
Set ptr . link := newnode
S5: End

Algorithm to insert an element at Last position in the Circular linked list

Linsert ( List, Item, start, info, link, newnode )


S1: Set newnode . info := item
Set newnode . link := null
S2: if ( start = null ), then
Set start : = newnode

Prepared By: Dr. Radha Mohan Pattanayak 14


Set newnode . link : = start
else
Set ptr := start
[ End of if-else ]
S3: Repeat step 3 while ( ptr . link != start )
Set ptr := ptr . link
[ End of while loop ]
S4: Set newnode . link := start
Set ptr . link := newnode
S5: End

Algorithm to insert an element at any position in the Circular linked list

Pinsert ( List, Item, start, info, link, newnode, pos )


S1: Set newnode . info := item
Set newnode . link := null
Set ptr := start
Set c := 1
S2: Repeat step 2 while ( c < pos - 1)
if ( ptr . link = start )
Print: ’ Sufficient nodes aren't present’
return
else
Set ptr := ptr . link
[ End of if-else ]
[ End of while loop ]
S3: Set newnode . link := ptr . link
Set ptr . link := newnode
S5: End

Algorithm to delete an element at First position in the Circular linked list

Fdelete ( List, Item, start, link )


S1: if ( start = null ), then
print: ‘UNDERFLOW’
return

Prepared By: Dr. Radha Mohan Pattanayak 15


else if ( start . link = start ), then
Set start := null
return
else
Set ptr := start
[ End of if-else ]
S2: Repeat step 2 while ( ptr . link != start )
Set ptr := ptr . link
[ End of while loop ]
S3: Set new := start
Set start := start . link
Set ptr . link := start
Set new . link := null
S4: End

Algorithm to delete an element at Last position in the Circular linked list

Ldelete ( List, Item, start, link )


S1: if ( start = null ), then
print: ‘UNDERFLOW’
return
else if ( start . link = start ), then
Set start := null
return
else
Set ptr1 := null
Set ptr2 := start
[ End of if-else ]
S2: Repeat step 2 while ( ptr2 . link != start )
Set ptr1 := ptr2
Set ptr2 := ptr2 . link
[ End of while loop ]
S3: Set ptr1 . link := start
Set ptr2 . link := null

Prepared By: Dr. Radha Mohan Pattanayak 16


S4: End

Algorithm to delete an element from any position in the Circular linked


list

Pdelete ( List, Item, start, info, pos )


S1: Set c := 1
Set ptr1 := null
Set ptr2 := start
S2: Repeat step 2 while ( c < pos )
if ( ptr2 . link = start ), then
Print: ‘Sufficient nodes aren't present’
return
else
Set ptr1 := ptr2
Set ptr2 := ptr2 . link
[ End of if-else ]
[ End of while ]
S3: Set ptr1 . link := ptr2 . link
Set ptr2 . link := null
S4: End

Queue :

It is a linear Array, where both the insertion and deletion operation can be performed
at two different ends.
Rear End
Front

Rear End:
The end where an insertion operation will perform is called as Rear end of the
Queue.
Front End:

Prepared By: Dr. Radha Mohan Pattanayak 17


The end where a deletion operation will perform is called as Front end of the Queue.
In Queue two pointers are available such as Front and Rear to point different location
inside the queue.
Front: It is a pointer which will point to the location of first element in the queue.
Rear: It is a pointer which will point to the location of last element in the queue.

Overflow condition of Queue:


Rear = Size or n is called as Overflow condition of the queue when the queue starts
from location 1.
Underflow condition Queue:
Front = 0 and Rear = 0 is called as Underflow condition of the queue when the
queue starts from location 1.
Algorithm to insert an element into Queue :
Qinsert (Queue, Front, Rear, Item, Size)
S1: Input: Item
S2: if (Rear = Size), then
print : ‘OVERFLOW’
return
[End of if]

S3: if (Front = 0 and Rear = 0), then


Set Front := Front +1
Set Rear := Rear +1
Set Queue [ Rear ] := item
else
Set Rear := Rear +1
Set Queue [ Rear ] := item
[end of if-else]
S4: exit

Algorithm to Delete an element from the Queue :


QDelete (Queue, Front, Rear, Item, Size)
S1: if ( Front = 0 ), then
Print : ‘UNDERFLOW’
return
[End of if]

Prepared By: Dr. Radha Mohan Pattanayak 18


S2: if (Front = Rear ), then
Set item := Queue [ Front ]
Set Front := 0
Set Rear := 0
else
Set Front := Front + 1
[end of if-else]
S3: exit

Circular Queue:
The linear Queue where the Front end of the queue will come after the Rear end then
such type of queue is said to be a Circular Queue.

Overflow condition of a Circular Queue:


(Front =1 & Rear = size) and (Front = Rear + 1) is called the overflow condition of
a circular queue.
Underflow condition of Circular Queue:
(Front =0 & Rear = 0) is called the underflow condition of a circular queue.

Algorithm to insert an element into CircularQueue :


CQinsert (CQ, Frt, Rer, Item, Size)
S1: Input: Item
S2: if ((Frt = 1 and Rer = Size) or (Frt = Rer +1)), then
print : ‘OVERFLOW’
return
[End of if]

S3: if (Frt = 0 and Rer = 0), then


Set Frt := Frt +1
Set Rer := Rer +1
Set CQ [ Rer ] := item

S4: if (Frt != 1 and Rer = size), then

Prepared By: Dr. Radha Mohan Pattanayak 19


Set Rer := 1
Set CQ [Rer] := item
else
Set Rer := Rer +1
Set CQ [Rer] : = item
[end of if-else]
S5: exit
Algorithm to delete an element from Circular Queue :
CQdelete (CQ, Frt, Rer, Item, Size)
S1: if (Rer = 0 and Frt = 0), then
print : ‘UNDERFLOW’
return
[End of if]

S2: if ( Frt = Rer ), then


Set Frt := 0
Set Rer := 0
return
[End of if]

S3: if ( Frt = size and Rer < Frt), then


Set Frt := 1
else
Set Frt := Frt +1
[end of if-else]
S4: exit

Prepared By: Dr. Radha Mohan Pattanayak 20


Question:
Process all the given below elements into the queue and print the position of each processing of the elements into the queue. Insert 5, Insert 2, Insert
7, Delete, Delete, Insert 4, Insert 3, Delete, Delete, Insert 9, Insert 6.

Overflow Condition

Prepared By: Dr. Radha Mohan Pattanayak 21


Question:
Process all the given below elements into the Circular queue and print the position of each processing of the elements into the Circular
queue. Insert 5, Insert 2, Insert 7, Delete, Delete, Insert 4, Insert 3, Delete, Delete, Insert 9, Insert 6.

Overflow Condition

Prepared By: Dr. Radha Mohan Pattanayak 22


Program for Insert, delete, and display operation in Queue

import java. util.*;


public class Trial
{
int queue[];
int front;
int rear;
int size;
Trial (int n)
{
queue = new int[n];
front = -1;
rear = -1;
size = n-1;
}
void Insert ( int item )
{
if ( rear = = size )
{
System. out. println ( " QUEUE OVERFLOW ");
return ;
}
if ( front = = 0 && rear = = 0)
{
rear = rear + 1;
front = front + 1;
queue [rear] = item;
}
else
{
rear = rear + 1;
queue [rear] = item;
}

Prepared By: Dr. Radha Mohan Pattanayak 23


}
void del()
{
int item;
if ( front = = -1)
{
System. out. println ( "QUEUE UNDERFLOW" );
return;
}
if ( front = = rear)
{
item = queue [front];
front = -1;
}
else
{
front = front + 1;
}
}
void display()
{
System. out. println ("The elements of the Queue are :");
for ( int i = 0; i < = rear; i++)
{
System. out. println ( queue [i] );
}
}
public static void main ( String args[] )
{
int n;
System. out. println ( "Enter the size of the Queue" );
Scanner sc = new Scanner (System.in);
n = sc. nextInt();
Trial t1=new Trial (n);

Prepared By: Dr. Radha Mohan Pattanayak 24


System. out. println ("Enter some elements into the Queue");
t1.Insert (1);
t1.Insert (2);
t1.Insert (3);
t1.display ();
t1.del ();
t1.del ();
t1.del ();
t1.del ();
t1.display ();
}
}
Implementation of Stack using Linked List

class Node
{
int info;
Node link;
}

class stack
{

static Node top = null;

public void push(int x)


{
Node newnode = new Node();
if (newnode == null) {
System.out.print("\nStack OVERFLOW");
return;
}
newnode.info = x;
newnode.link = top;

Prepared By: Dr. Radha Mohan Pattanayak 25


top = newnode;
}

public void pop()


{
if (top == null) {
System.out.print("\nStack Underflow");
return;
}
top = top.link;
}

public void display()


{
System.out.printf("\n");
if (top == null) {
System.out.printf("\nStack Underflow");
return;
}
else {
Node ptr = top;
while (ptr != null)
{
System.out.printf("%d->", ptr.info);
ptr = ptr.link;
}
}
}

public static void main(String[] args)


{
stack s = new stack();
s.push(11);
s.push(22);

Prepared By: Dr. Radha Mohan Pattanayak 26


s.push(33);
s.push(44);
s.display();
System.out.printf("\nTop element is %d\n", top.info);
s.pop();
s.pop();
System.out.printf("\nTop element is %d\n", top.info);
s.display();
}
}
Implementation of Circular Queue

import java. util.*;


public class Trial
{
static int cqueue[];
static int front;
static int rear;
static int size;
Trial (int n)
{
front= -1;
rear= -1;
size = n;
cqueue = new int[n];
}
void Insert ( int item )
{
if ((front==0 && rear == size-1)||(front==rear+1))
{
System. out. println ( " QUEUE OVERFLOW ");
return ;
}
if ( front == -1 && rear == -1)

Prepared By: Dr. Radha Mohan Pattanayak 27


{
rear = 0;
front = 0;
cqueue [rear] = item;
}
else if(front>0 && rear==size-1)
{
rear = 0;
cqueue [rear] = item;
}
else
{
rear=rear+1;
cqueue [rear] = item;
}

System. out. println ("Front=" + front + "rear=" + rear);


display ();
}
void del()
{

if ( front == -1)
{
System. out. println ( "QUEUE UNDERFLOW" );
return;
}

if ( front == rear)
{
front = -1;
rear=-1;
}
else if(front==size-1 && rear<front)

Prepared By: Dr. Radha Mohan Pattanayak 28


{
front = 0;
}
else
{
front = front + 1;
}
System. out. println ("Front=" + front + "rear=" + rear);
display ();

}
void display()
{
int i=front,count=cqueue.length;
System. out. println ("The elements of the Queue are :");
if(front==-1 && rear==-1)
System. out. println ("No elements in the Queue:");
else if(front<rear)
{
while(i<=rear)
{
System. out. println ( "i=" + i + ":" + cqueue[i]);
++i;
}
}
else if(front>rear)
{
i=0;
while(i!=-1)
{
System. out. println ( "i=" + i + ":" + cqueue[i]);
if (i==rear)
i=front;
else if(i==size-1)

Prepared By: Dr. Radha Mohan Pattanayak 29


i=-1;
else
++i;
}
}
}
public static void main ( String args[] )
{
int n;
System. out. println ( "Enter the size of the Queue" );
Scanner sc = new Scanner (System.in);
n = sc. nextInt();
Trial t1=new Trial (n);
t1.Insert (1);
t1.Insert (2);
t1.Insert (3);
t1.Insert (4);
t1.display ();
t1.del ();
t1.display ();
t1.del ();
t1.del ();
t1.display ();
}
}

Prepared By: Dr. Radha Mohan Pattanayak 30

You might also like