Download presentation
Presentation is loading. Please wait.
1
KENDRIYA VIDYALAYA SANGATHAN (AGRA REGION)
COMPUTER SCIENCE- XII DATA STRUCTURE IN C++ (LINKED LIST, STACK & QUEUE) VENUE: K V NO.2 AGRA CANTT, AGRA
2
DATA STRUCTURES:- LINKED LIST STACK QUEUE BY:- DEEPAK SHARMA
PGT COMPUTER SCIENCE, KV2 AGRA
3
PRE KNOWLEDGE REQUIRED:-
1. C++ MEMORY MAP 2. TYPES OF MEMORY ALLOCATION 3. BASIC CONCEPTS OF POINTERS 4. IMPORTANCE OF DATA TYPES IN POINTERS 5. SELF REFENCIAL STRUCTURE
4
C++ MEMORY MAP THERE ARE FOUR REGIONS IN C++ MEMORY MAP (MEMORY MEANS MAIN MEMORY (RAM) 1. PROGRAM CODE 2. GLOBAL VARIABLE 3. STACK 4. HEAP
5
MEMORY ALLOCATION STATIC MEMORY ALLOCATION
When the amount of memory to be allocated is known beforehand and the memory allocated during compile time itself, it is known as static memory allocation. For example:- int x; DYNAMIC MEMORY ALLOCATION:- When the amount of memory to be allocated is not known beforehand rather it is required to allocate memory as and when required during runtime. This type of memory allocation is known as dynamic memory allocation. C++ offers two operators for dynamic memory allocation: new 2. delete The memory allocated dynamically using new operator must be de- allocated by delete operator
6
Dynamic Memory Allocation:- General Form:- <data type> <pointer variable>= new <data type> for example:- int * x; x=new int; OR int * x=new int;
7
Importance of data type in pointers:-
float x; // normal variable int *y; // pointer type variable Y=&x; float x 4 bytes Integer type pointer will access only two bytes from first byte. So there will be loss of information.
8
Self Referential Structure
struct Node { Int info; Node * link; }; Node ob1; Node * Newptr; // wild pointer of type Node Newptr=new Node;
9
Ob1.info=5; Ob1.link=Null; Newptr info=5; Newptrlink=Null;
Stack (LIFO) Data Structures Queue(FIFO) Array Linked List Array Linked List
10
BEGINNING √ INSERTION MIDDLE LINKED LIST DELETION MIDDLE END END √
11
INSERTION IN BEGINNING OF THE LINKED LIST
START 1000 NEWPTR=7000 1000 3000 2000 4000
12
HOW TO CREATE NEW NODE DYNAMICALLY
Node * NEWPTR; NEWPTR= new Node; NEWPTRinfo=17; NEWPTRLink=NULL; NEWPTR=7000 Link= NULL
13
Logic : If (START=NULL) START=NEWPTR; else { NEWPTRLink=START; } OR SAVE=START; NEWPTRLink=SAVE;
14
INSERTION IN END OF THE LINKED LIST
START 1000 NEWPTR=7000 1000 3000 2000 4000
15
Logic:- If (START==NULL) START=REAR=NEWPTR; else { REARLink=NEWPTR;
}
16
DELETION FROM THE BEGENINNG OF THE LINKED LIST
START 1000 1000 3000 2000 4000
17
Logic:- If START=NULL PRINT UNDERFLOW; ELSE { TEMP=START;
START=STARTLink; Delete TEMP; }
18
THANK YOU
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.