SlideShare a Scribd company logo
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.1
andreas_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 Rewriting
Eelco 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 III
Ajit Nayak
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
 
Primitives in Generics
Primitives in GenericsPrimitives in Generics
Primitives in Generics
Ivan Ivanov
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
Intro 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
 
java8
java8java8
Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
Eelco 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 Operators
Sunil 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 @PoliMi
Davide Chicco
 
An introduction to R
An introduction to RAn 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
sumitbardhan
 
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
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
Badiuzzaman Pranto
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
Rumman 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 File
Deyvessh kumar
 
Aae oop xp_12
Aae oop xp_12Aae oop xp_12
Aae oop xp_12
Niit 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 Queues
Ferdin Joe John Joseph PhD
 
Strings
StringsStrings
Strings
Nilesh Dalvi
 
Introduction to java programming part 2
Introduction to java programming  part 2Introduction to java programming  part 2
Introduction to java programming part 2
university of education,Lahore
 
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
SnehilKeshari
 
stack & queue
stack & queuestack & queue
stack & queue
manju rani
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
Nilesh Dalvi
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
Michael Redlich
 
linked list in c++
linked list in c++linked list in c++
linked list in c++
YaminiLakshmi Meduri
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
Michael Redlich
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
Nilesh Dalvi
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
Usha Mahalingam
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
Shahjahan 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 2020
Joseph Kuo
 
01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo01 stack 20160908_jintaek_seo
01 stack 20160908_jintaek_seo
JinTaek Seo
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
Nguync91368
 
Java introduction
Java introductionJava introduction
Java introduction
Samsung Electronics Egypt
 
Templates
TemplatesTemplates
Templates
Nilesh Dalvi
 
1 c prog1
1 c prog11 c prog1
1 c prog1
CollegeStation
 
2 b queues
2 b queues2 b queues
2 b queues
Nguync91368
 
DSA-Day-2-PS.pptx
DSA-Day-2-PS.pptxDSA-Day-2-PS.pptx
DSA-Day-2-PS.pptx
amanbhogal7
 

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

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Undress Baby
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Envertis Software Solutions
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 

Recently uploaded (20)

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfRevolutionizing Visual Effects Mastering AI Face Swaps.pdf
Revolutionizing Visual Effects Mastering AI Face Swaps.pdf
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise EditionWhy Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
Why Choose Odoo 17 Community & How it differs from Odoo 17 Enterprise Edition
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 

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