0% found this document useful (0 votes)
15 views3 pages

Data Structures: Stacks, Queues, Linked Lists

Chapter 3

Uploaded by

chandu chandran
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)
15 views3 pages

Data Structures: Stacks, Queues, Linked Lists

Chapter 3

Uploaded by

chandu chandran
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

CHAPTER 3: DATA STRUCTURES AND OPERATORS

Data Structures

A data structure is a way of organizing similar or dissimilar related data items as a single unit. It allows us to represent

and process a group of data as a single unit.

Operation on Data Structures

 Traversal:- It is the process of visiting elements in a data structure.

 Searching:- It is the process of finding the location of an element.

 Inserting:- It is the process adding a new data.

 Deleting:- It is the process removing an element.

 Merging:- It is the process arranging elements in a data structure.

Stack

 Stack is a linear data structure.

 It follows the LIFO (Last In, First Out) principle.

 Adding an item into the stack is called Push

 Removing an item from this stack is called the Pop.

Operations on Stack

Push Operation Algorithm Pop Operation Algorithm

Start Start

If (TOS < N) Then If (TOS > -1) Then

TOS = TOS + 1 VAL = STACK[TOS]


STACK[TOS] = VAL TOS = TOS - 1

Else Else

Print “Stack Overflow” Print “Stack Underflow”

End of if End of if

Stop Stop

Underflow and Overflow

Underflow occurs when a pop operation is attempted on an empty stack, while overflow arises when a push operation is

attempted on a stack that has reached its maximum capacity.

Queue

 Queue is a linear data structure.

 It follows the FIFO (First In, Last Out) principle.

 The queue has two ends; the Front and the Rear .

 Items are added at the rear end and removed from the front end.

Operations on Queue

Insertion Algorithm Deletion Algorithm

Start Start

If (REAR == -1) Then If (FRONT > -1 AND FRONT < REAR) Then

FRONT = REAR = 0 VAL = Q[FRONT]

Q[REAR] = VAL FRONT = FRONT + 1

Else if (REAR < N) Then Else

REAR = REAR + 1 Print “Queue Underflow”

Q[REAR] = VAL End of if

Else If (FRONT > FRONT) Then

Print “Queue Overflow” FRONT = FRONT = -1

End of if End of if

Stop Stop

Circular Queue

In a Circular queue the two end points meet. Hence, after the highest index position of front or rear, it jump back to 0

Linkedlist

 It is a collection of nodes.

 It is a dynamic data structure, hence there is no limit to the number of items.

 A node in a linked list contains data and the address of the next element.
 The address in the node is also called a link.

 It is arranged in such a way that the first node contains the address of the second node, the second node contains the

address of the third node, and so on.

 The last node contains the value null in the link part.

 The address of the first node is stored in a variable called start.

You might also like