SlideShare a Scribd company logo
1 of 39
What is
Array , Stack and Queue ??
Presented By: Presented To:
Adeel Kamran 03 Dr.Sajid Ali
Ali Raza Sheikh 04
Ali Raza 07
University of Educatuon Lahore D.G Khan
Campus
1
DATA
STRUCTURE
LINEAR DATA
STRUCTURE
Array Link list Stack Queue
NON LINEAR
DATA
STRUCTURE
University of Educatuon Lahore D.G Khan Campus 2
What is Linear Data Structure
In linear data structure, data is arranged in
linear sequence.
 Data items can be traversed in a single
run.
 In linear data structure elements are
accessed or placed in contiguous(together in
sequence) memory location.
University of Educatuon Lahore D.G Khan Campus 3
Array
University of Educatuon Lahore D.G Khan Campus 4
Array
• Array is type of linear data Structure
• In array that store the same data type having different index location
• Array index is start from zero
• Array having fix size
University of Educatuon Lahore D.G Khan Campus 5
Array Examples
• In real world array is widely use in cloth making
• Array of people in library
• Array of process
University of Educatuon Lahore D.G Khan Campus 6
Array operations
• Insert()
to add element to array
• Search()
to find element in array
• Update()
to update existing element in an array
University of Educatuon Lahore D.G Khan Campus 7
C++ implementation of Array insertion
#include<iostream>
using namespace std;
int main(){
int arr[]={10,20,30,40,50};
int item = 25;
int k = 0;
int n=5;
int j=n;
for(int i=0;i<5;i++){
cout<<"value at index = "<<i<<" "<<arr[i]<<endl;
}
University of Educatuon Lahore D.G Khan Campus 8
void update()
{
int value;
int loc;
cout<<"Enter Element for update in array ";
cin>>value;
cout<<"Enter location in an array (0-4) ";
cin>>loc;
arr[loc] = value;
n=n+1;
cout<<"Enter Element of you want to add = ";
cin>>item;
cout<<"Enter location which you want of add elemnt =
";
cin>>location;
while(j>=location){
arr[j+1]=arr[j];
j--;
}
arr[location]=item;
for(int i=0;i<6;i++){
cout<<"Value ="<<i<<" "<<arr[i]<<endl;
}
update();
search();
}//end of main
University of Educatuon Lahore D.G Khan Campus 9
Void search(){
cout<<"Enter value fo search = ";
cin>>item;
for(i =0;i<5;i++){
if(arr[i]==item){
key = true;
break;
}
}
if(key==true){
cout<<"value found at index "<<i;
}
else{
cout<<"value not found ";
}
}
University of Educatuon Lahore D.G Khan Campus 10
Stack
University of Educatuon Lahore D.G Khan Campus 11
WHAT Is
 A stack is called a last-in-first-out (LIFO)
collection. This means that the last thing we
added (pushed) is the first thing that gets
pulled (popped) off.
• A stack is a sequence of items that are
accessible at only one end of the sequence.
University of Educatuon Lahore D.G Khan Campus 12
EXAMPLES OF STACK:
University of Educatuon Lahore D.G Khan Campus 13
Operations that can be performed on
STACK:
 PUSH.
 POP.
University of Educatuon Lahore D.G Khan Campus 14
Last In First Out
B
A
D
C
B
A
C
B
A
E
D
C
B
A
top
top
top
top
top
A
University of Educatuon Lahore D.G Khan Campus 15
Array-based Stack Implementation
• Allocate an array of some size (pre-defined)
• Maximum N elements in stack
• Bottom stack element stored at element 0
• last index in the array is the top
• Increment top when one element is pushed, decrement after pop
University of Educatuon Lahore D.G Khan Campus 16
#include<iostream>
#include<conio.h>
#define SIZE 10
using namespace std;
static int top=-1;
class stack
{
private:
int ar[SIZE];
public:
void push(int item);
void pop();
void peep();
};// end of class
void stack::push(int item)
{
if(top==SIZE-1)
cout<<"nThe Stack is Full!!!";
else
{ ar[++top]=item;
cout<<"nElement succesfully pushed in the Stack!!!";
}
}// end of void push
void stack::pop()
{
if(top<0)
cout<<"nStack Under flow!!!";
else
{ top--;
cout<<"nElement sucessfully popped from the Stack!!!";
}
}// end of void pop
void stack::peep()
{ if(top<0)
cout<<"nThe Stack is Empty it cannot be Peeped!!!";
else
for(int i=top;i>=0;i--)
cout<<ar[i]<<" ";
}// end of void peep
University of Educatuon Lahore D.G Khan Campus 17
int main()
{
char choice;
int ch,num;
stack ob;
do
{
cout<<"nntttS T A C K O P E R A T I O N S";
cout<<"nttt-------------------------------";
cout<<"nn1.PUSH";
cout<<"n2.POP";
cout<<"n3.PEEP";
cout<<"n4.EXIT";
cout<<"nnEnter your choice:";
cin>>ch;
switch(ch)
{
case 1: cout<<"nEnter the Element you want to Push:";
cin>>num;
ob.push(num);
break;// end of case1
case 2: ob.pop();
break;// end of case2
case 3: ob.peep();
break;// end of case3
case 4: exit(0);// end of case4
default: cout<<"nPlease Enter a Valid Choice(1-4)!!!";
}// end of switch
cout<<"nDo you want to Continue(Y/N):";
cin>>choice;
}// end of do
while(choice=='y' || choice=='y');
getch();
}// end of main
University of Educatuon Lahore D.G Khan Campus 18
The Towers of Hanoi
A Stack-based Application
• GIVEN: three poles
• a set of discs on the first pole, discs of different sizes, the smallest
discs at the top
• GOAL: move all the discs from the left pole to the right one.
• CONDITIONS: only one disc may be moved at a time.
• A disc can be placed either on an empty pole or on top of a larger
disc.
University of Educatuon Lahore D.G Khan Campus 19
Towers of Hanoi
University of Educatuon Lahore D.G Khan Campus 20
Towers of Hanoi
University of Educatuon Lahore D.G Khan Campus 21
Towers of Hanoi
University of Educatuon Lahore D.G Khan Campus 22
Towers of Hanoi
University of Educatuon Lahore D.G Khan Campus 23
APPLICATIONS OF STACKS ARE:
I. Reversing Strings:
• A simple application of stack is reversing strings.
To reverse a string , the characters of string are
pushed onto the stack one by one as the string
is read from left to right.
• Once all the characters
of string are pushed onto stack, they are
popped one by one. Since the character last
pushed in comes out first, subsequent pop
operation results in the reversal of the string.
University of Educatuon Lahore D.G Khan Campus 24
For example:
To reverse the string ‘REVERSE’ the string is
read from left to right and its characters are
pushed . LIKE:
onto a stack.
University of Educatuon Lahore D.G Khan Campus 25
II. Checking the validity of an expression
containing nested parenthesis:
• Stacks are also used to check whether a given
arithmetic expressions containing nested
parenthesis is properly parenthesized.
• The program for checking the validity of an
expression verifies that for each left
parenthesis
braces or bracket ,there is a corresponding
closing symbol and symbols are appropriately
nested.
University of Educatuon Lahore D.G Khan Campus 26
For example:
VALID INPUTS INVALID INPUTS
{ }
( { [ ] } )
{ [ ] ( ) }
[ { ( { } [ ] ( {
})}]
{ ( }
( [ ( ( ) ] )
{ } [ ] )
[ { ) } ( ] } ]
University of Educatuon Lahore D.G Khan Campus 27
An Other Example of Stack in use of
• POSTFIX
• PREFIX
• INFIX
University of Educatuon Lahore D.G Khan Campus 28
Example: postfix expressions
• Postfix notation is another way of writing arithmetic
expressions.
• In postfix notation, the operator is written after the
two operands.
infix: 2+5 postfix: 2 5 +
• Expressions are evaluated from left to right.
• Precedence rules and parentheses are never
needed!!
University of Educatuon Lahore D.G Khan Campus 29
Example: postfix expressions
(cont.)
University of Educatuon Lahore D.G Khan Campus 30
Postfix expressions:
Algorithm using stacks (cont.)
University of Educatuon Lahore D.G Khan Campus 31
How to make header file in C++
University of Educatuon Lahore D.G Khan Campus 32
#ifndef HEADER_FILE_NAME
#ifdef HEADER_FILE_NAME
// write header file code here
// save this file *.h extension
// and save this file
// C:Program Files (x86)Dev-CppMinGW64include
#ifdef
University of Educatuon Lahore D.G Khan Campus 33
Queue
University of Educatuon Lahore D.G Khan Campus 34
Queue
• Queue is a type of data structure.
• Queue is based on Technique FIFO(first in first out).
• It store the new object at the end of previous object.
• It remove the object that have firstly entered in Queue.
University of Educatuon Lahore D.G Khan Campus 35
Example
• People waiting to buy tickets.
• Single traffic line.
University of Educatuon Lahore D.G Khan Campus 36
Operations on Queue
• Enqueue();
In Enqueue is function, we can insert an object in Queue.
• Dequeue();
In Dequeue is function, can remove the object in Queue.
University of Educatuon Lahore D.G Khan Campus 37
#ifndef Queue
#ifdef Queue
#include<iostream>
using namespace std;
class Queue{
public:
int arr[5]; int size=5; int top;
int count, first;
Queue(){
first=-1;
count=0;
top=0;
}//end of constructor
void enqueue(int data){
if(count>=size){
cout<<"Queue is full"<<endl;
}
else{
first++;
arr[first]=data;
count++;
cout<<"data Added to Queue"<<endl;
}//end of else
}//end of enqueue
University of Educatuon Lahore D.G Khan Campus 38
void dequeue(){
if(count<=0){
cout<<"Queue is empy"<<endl;
}
else{
cout<<"value is Dequeuing =
"<<arr[top]<<endl;
top++;
count--;
}//end of else
}//end of dequeue
};// end of class
#enfif
#include<Queue.h>
int main(){
Queue obj;
obj.dequeue();
obj.enqueue(10);
obj.enqueue(20);
obj.enqueue(30);
obj.dequeue();
}
University of Educatuon Lahore D.G Khan Campus 39

More Related Content

What's hot

Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1andreas_schultz
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingEelco Visser
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIAjit Nayak
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesEelco Visser
 
Primitives in Generics
Primitives in GenericsPrimitives in Generics
Primitives in GenericsIvan Ivanov
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm ComplexityIntro C# Book
 
Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Alexander Podkhalyuzin
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionEelco Visser
 
Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...
Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...
Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...Thanos Zolotas
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
Doctoral Thesis Dissertation 2014-03-20 @PoliMi
Doctoral Thesis Dissertation 2014-03-20 @PoliMiDoctoral Thesis Dissertation 2014-03-20 @PoliMi
Doctoral Thesis Dissertation 2014-03-20 @PoliMiDavide Chicco
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7sumitbardhan
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Udayan Khattry
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and AnswersRumman Ansari
 
stacks and queues class 12 in c++
stacks and  queues class 12 in c++stacks and  queues class 12 in c++
stacks and queues class 12 in c++Khushal Mehta
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project FileDeyvessh kumar
 
Aae oop xp_12
Aae oop xp_12Aae oop xp_12
Aae oop xp_12Niit Care
 

What's hot (20)

Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part III
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
 
Primitives in Generics
Primitives in GenericsPrimitives in Generics
Primitives in Generics
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
 
Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)Under the hood of scala implicits (kl10tch 10.03.2015)
Under the hood of scala implicits (kl10tch 10.03.2015)
 
java8
java8java8
java8
 
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
 
Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...
Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...
Bridging Proprietary Modelling and Open-Source Model Management Tools: The Ca...
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
Doctoral Thesis Dissertation 2014-03-20 @PoliMi
Doctoral Thesis Dissertation 2014-03-20 @PoliMiDoctoral Thesis Dissertation 2014-03-20 @PoliMi
Doctoral Thesis Dissertation 2014-03-20 @PoliMi
 
An introduction to R
An introduction to RAn introduction to R
An introduction to R
 
358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7358 33 powerpoint-slides_7-structures_chapter-7
358 33 powerpoint-slides_7-structures_chapter-7
 
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
 
stacks and queues class 12 in c++
stacks and  queues class 12 in c++stacks and  queues class 12 in c++
stacks and queues class 12 in c++
 
Data Structure Project File
Data Structure Project FileData Structure Project File
Data Structure Project File
 
Aae oop xp_12
Aae oop xp_12Aae oop xp_12
Aae oop xp_12
 

Similar to Data structure

Data Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and QueuesData Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and QueuesFerdin Joe John Joseph PhD
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesSnehilKeshari
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++Nilesh Dalvi
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template LibraryNilesh Dalvi
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURESUsha Mahalingam
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation xShahjahan Samoon
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020Joseph Kuo
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seoJinTaek Seo
 
DSA-Day-2-PS.pptx
DSA-Day-2-PS.pptxDSA-Day-2-PS.pptx
DSA-Day-2-PS.pptxamanbhogal7
 

Similar to Data structure (20)

Data Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and QueuesData Structures and Algorithm - Week 3 - Stacks and Queues
Data Structures and Algorithm - Week 3 - Stacks and Queues
 
Strings
StringsStrings
Strings
 
Introduction to java programming part 2
Introduction to java programming  part 2Introduction to java programming  part 2
Introduction to java programming part 2
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
stack & queue
stack & queuestack & queue
stack & queue
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
 
linked list in c++
linked list in c++linked list in c++
linked list in c++
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 
Java introduction
Java introductionJava introduction
Java introduction
 
Templates
TemplatesTemplates
Templates
 
1 c prog1
1 c prog11 c prog1
1 c prog1
 
2 b queues
2 b queues2 b queues
2 b queues
 
DSA-Day-2-PS.pptx
DSA-Day-2-PS.pptxDSA-Day-2-PS.pptx
DSA-Day-2-PS.pptx
 

Recently uploaded

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 

Recently uploaded (20)

The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Data structure

  • 1. What is Array , Stack and Queue ?? Presented By: Presented To: Adeel Kamran 03 Dr.Sajid Ali Ali Raza Sheikh 04 Ali Raza 07 University of Educatuon Lahore D.G Khan Campus 1
  • 2. DATA STRUCTURE LINEAR DATA STRUCTURE Array Link list Stack Queue NON LINEAR DATA STRUCTURE University of Educatuon Lahore D.G Khan Campus 2
  • 3. What is Linear Data Structure In linear data structure, data is arranged in linear sequence.  Data items can be traversed in a single run.  In linear data structure elements are accessed or placed in contiguous(together in sequence) memory location. University of Educatuon Lahore D.G Khan Campus 3
  • 4. Array University of Educatuon Lahore D.G Khan Campus 4
  • 5. Array • Array is type of linear data Structure • In array that store the same data type having different index location • Array index is start from zero • Array having fix size University of Educatuon Lahore D.G Khan Campus 5
  • 6. Array Examples • In real world array is widely use in cloth making • Array of people in library • Array of process University of Educatuon Lahore D.G Khan Campus 6
  • 7. Array operations • Insert() to add element to array • Search() to find element in array • Update() to update existing element in an array University of Educatuon Lahore D.G Khan Campus 7
  • 8. C++ implementation of Array insertion #include<iostream> using namespace std; int main(){ int arr[]={10,20,30,40,50}; int item = 25; int k = 0; int n=5; int j=n; for(int i=0;i<5;i++){ cout<<"value at index = "<<i<<" "<<arr[i]<<endl; } University of Educatuon Lahore D.G Khan Campus 8
  • 9. void update() { int value; int loc; cout<<"Enter Element for update in array "; cin>>value; cout<<"Enter location in an array (0-4) "; cin>>loc; arr[loc] = value; n=n+1; cout<<"Enter Element of you want to add = "; cin>>item; cout<<"Enter location which you want of add elemnt = "; cin>>location; while(j>=location){ arr[j+1]=arr[j]; j--; } arr[location]=item; for(int i=0;i<6;i++){ cout<<"Value ="<<i<<" "<<arr[i]<<endl; } update(); search(); }//end of main University of Educatuon Lahore D.G Khan Campus 9
  • 10. Void search(){ cout<<"Enter value fo search = "; cin>>item; for(i =0;i<5;i++){ if(arr[i]==item){ key = true; break; } } if(key==true){ cout<<"value found at index "<<i; } else{ cout<<"value not found "; } } University of Educatuon Lahore D.G Khan Campus 10
  • 11. Stack University of Educatuon Lahore D.G Khan Campus 11
  • 12. WHAT Is  A stack is called a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off. • A stack is a sequence of items that are accessible at only one end of the sequence. University of Educatuon Lahore D.G Khan Campus 12
  • 13. EXAMPLES OF STACK: University of Educatuon Lahore D.G Khan Campus 13
  • 14. Operations that can be performed on STACK:  PUSH.  POP. University of Educatuon Lahore D.G Khan Campus 14
  • 15. Last In First Out B A D C B A C B A E D C B A top top top top top A University of Educatuon Lahore D.G Khan Campus 15
  • 16. Array-based Stack Implementation • Allocate an array of some size (pre-defined) • Maximum N elements in stack • Bottom stack element stored at element 0 • last index in the array is the top • Increment top when one element is pushed, decrement after pop University of Educatuon Lahore D.G Khan Campus 16
  • 17. #include<iostream> #include<conio.h> #define SIZE 10 using namespace std; static int top=-1; class stack { private: int ar[SIZE]; public: void push(int item); void pop(); void peep(); };// end of class void stack::push(int item) { if(top==SIZE-1) cout<<"nThe Stack is Full!!!"; else { ar[++top]=item; cout<<"nElement succesfully pushed in the Stack!!!"; } }// end of void push void stack::pop() { if(top<0) cout<<"nStack Under flow!!!"; else { top--; cout<<"nElement sucessfully popped from the Stack!!!"; } }// end of void pop void stack::peep() { if(top<0) cout<<"nThe Stack is Empty it cannot be Peeped!!!"; else for(int i=top;i>=0;i--) cout<<ar[i]<<" "; }// end of void peep University of Educatuon Lahore D.G Khan Campus 17
  • 18. int main() { char choice; int ch,num; stack ob; do { cout<<"nntttS T A C K O P E R A T I O N S"; cout<<"nttt-------------------------------"; cout<<"nn1.PUSH"; cout<<"n2.POP"; cout<<"n3.PEEP"; cout<<"n4.EXIT"; cout<<"nnEnter your choice:"; cin>>ch; switch(ch) { case 1: cout<<"nEnter the Element you want to Push:"; cin>>num; ob.push(num); break;// end of case1 case 2: ob.pop(); break;// end of case2 case 3: ob.peep(); break;// end of case3 case 4: exit(0);// end of case4 default: cout<<"nPlease Enter a Valid Choice(1-4)!!!"; }// end of switch cout<<"nDo you want to Continue(Y/N):"; cin>>choice; }// end of do while(choice=='y' || choice=='y'); getch(); }// end of main University of Educatuon Lahore D.G Khan Campus 18
  • 19. The Towers of Hanoi A Stack-based Application • GIVEN: three poles • a set of discs on the first pole, discs of different sizes, the smallest discs at the top • GOAL: move all the discs from the left pole to the right one. • CONDITIONS: only one disc may be moved at a time. • A disc can be placed either on an empty pole or on top of a larger disc. University of Educatuon Lahore D.G Khan Campus 19
  • 20. Towers of Hanoi University of Educatuon Lahore D.G Khan Campus 20
  • 21. Towers of Hanoi University of Educatuon Lahore D.G Khan Campus 21
  • 22. Towers of Hanoi University of Educatuon Lahore D.G Khan Campus 22
  • 23. Towers of Hanoi University of Educatuon Lahore D.G Khan Campus 23
  • 24. APPLICATIONS OF STACKS ARE: I. Reversing Strings: • A simple application of stack is reversing strings. To reverse a string , the characters of string are pushed onto the stack one by one as the string is read from left to right. • Once all the characters of string are pushed onto stack, they are popped one by one. Since the character last pushed in comes out first, subsequent pop operation results in the reversal of the string. University of Educatuon Lahore D.G Khan Campus 24
  • 25. For example: To reverse the string ‘REVERSE’ the string is read from left to right and its characters are pushed . LIKE: onto a stack. University of Educatuon Lahore D.G Khan Campus 25
  • 26. II. Checking the validity of an expression containing nested parenthesis: • Stacks are also used to check whether a given arithmetic expressions containing nested parenthesis is properly parenthesized. • The program for checking the validity of an expression verifies that for each left parenthesis braces or bracket ,there is a corresponding closing symbol and symbols are appropriately nested. University of Educatuon Lahore D.G Khan Campus 26
  • 27. For example: VALID INPUTS INVALID INPUTS { } ( { [ ] } ) { [ ] ( ) } [ { ( { } [ ] ( { })}] { ( } ( [ ( ( ) ] ) { } [ ] ) [ { ) } ( ] } ] University of Educatuon Lahore D.G Khan Campus 27
  • 28. An Other Example of Stack in use of • POSTFIX • PREFIX • INFIX University of Educatuon Lahore D.G Khan Campus 28
  • 29. Example: postfix expressions • Postfix notation is another way of writing arithmetic expressions. • In postfix notation, the operator is written after the two operands. infix: 2+5 postfix: 2 5 + • Expressions are evaluated from left to right. • Precedence rules and parentheses are never needed!! University of Educatuon Lahore D.G Khan Campus 29
  • 30. Example: postfix expressions (cont.) University of Educatuon Lahore D.G Khan Campus 30
  • 31. Postfix expressions: Algorithm using stacks (cont.) University of Educatuon Lahore D.G Khan Campus 31
  • 32. How to make header file in C++ University of Educatuon Lahore D.G Khan Campus 32
  • 33. #ifndef HEADER_FILE_NAME #ifdef HEADER_FILE_NAME // write header file code here // save this file *.h extension // and save this file // C:Program Files (x86)Dev-CppMinGW64include #ifdef University of Educatuon Lahore D.G Khan Campus 33
  • 34. Queue University of Educatuon Lahore D.G Khan Campus 34
  • 35. Queue • Queue is a type of data structure. • Queue is based on Technique FIFO(first in first out). • It store the new object at the end of previous object. • It remove the object that have firstly entered in Queue. University of Educatuon Lahore D.G Khan Campus 35
  • 36. Example • People waiting to buy tickets. • Single traffic line. University of Educatuon Lahore D.G Khan Campus 36
  • 37. Operations on Queue • Enqueue(); In Enqueue is function, we can insert an object in Queue. • Dequeue(); In Dequeue is function, can remove the object in Queue. University of Educatuon Lahore D.G Khan Campus 37
  • 38. #ifndef Queue #ifdef Queue #include<iostream> using namespace std; class Queue{ public: int arr[5]; int size=5; int top; int count, first; Queue(){ first=-1; count=0; top=0; }//end of constructor void enqueue(int data){ if(count>=size){ cout<<"Queue is full"<<endl; } else{ first++; arr[first]=data; count++; cout<<"data Added to Queue"<<endl; }//end of else }//end of enqueue University of Educatuon Lahore D.G Khan Campus 38
  • 39. void dequeue(){ if(count<=0){ cout<<"Queue is empy"<<endl; } else{ cout<<"value is Dequeuing = "<<arr[top]<<endl; top++; count--; }//end of else }//end of dequeue };// end of class #enfif #include<Queue.h> int main(){ Queue obj; obj.dequeue(); obj.enqueue(10); obj.enqueue(20); obj.enqueue(30); obj.dequeue(); } University of Educatuon Lahore D.G Khan Campus 39