Chapter 1
Chapter 1
Structures
Principles of Data Structures using C and C++ by Vinu V Das
Course Contents
Trees
Graphs Linked
Introduction
to Data Lists
Structures
Introduction to
Algorithms Stacks
Arrays
Sorting and
Memory Queues Searching
Management
For Your Information
For Lectures and other course materials
www.facebook.com/groups/pafkiet.ads.sp15
Non Linear
Example : int x
• Only numeric whole numbers can be stored in x, i.e. 0,1,2,3,4,5,6,7,8,9 etc.
• Only numeric operation can be performed on x, i.e. addition, subtraction etc.
Some times primitive data types are not enough to solve all the problems.
• Like, Complex number arithmetic
Need to implement new data type from primitive ones.
integer S Magnitude
Data
Program Type
Set of
Algorithm
Operations
Non-
Primitive DS
Primitive DS
Array Subscript:
A value or expression enclosed in brackets [ ] after the array name, specifying which array element to access.
Example :
struct student
{
string name;
int s_id;
student * next;
}
Insertion and deletion can takes place only at one end of the stack, called top of stack (TOS)
Example :
Consider a stack of dishes as shown in the figure.
Note that new dishes are entered at the top of stack.
And can be removed only from the top of stack.
Applications:
Function calls
Evaluating post-fix expressions
Insertion can takes place only at one end of the queue, called rear(back) of the queue.
Deletion can takes place only at one end of the queue, called front of the queue.
Example :
Consider a queue of peoples as shown in the figure.
Note that new person can enter the line from the back.
A person is only allowed to leave the line from front.
Applications:
Jobs submitted to printer is on FIFO basis.
Process scheduling in OS
Example :
Consider following employee data
Example :
Suppose air-line only flies between the cities connected by line.