Module 2
Module 2
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.
6 .
Top 5 9
4 7
3 5
2 3
1 2
Index Element
Structure of a STACK
6 1 6
5 9 5
4 7 4
3 5 3
2 3 2
1 2 1
( (
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
(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
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.
30 7 40 4 50 9 60
5 7 4 9
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
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.
Algorithm to delete an element from Last position in the Double linked list
30 7 40 4 50 9 20 5
5 7 4 9
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:
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
Overflow Condition
class Node
{
int info;
Node link;
}
class stack
{
if ( front == -1)
{
System. out. println ( "QUEUE UNDERFLOW" );
return;
}
if ( front == rear)
{
front = -1;
rear=-1;
}
else if(front==size-1 && rear<front)
}
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)