SlideShare a Scribd company logo
1 of 13
Download to read offline
Mohammed Sikander
Team Lead
CranesVarsity
Mohammed.sikander@cranessoftware.com
STACK
 void push(int )
 void pop( )
 bool empty( )
 int & top( )
QUEUE
 void push(int)
 void pop( )
 bool empty( )
 int &front( )
Sikander 2
STACK
 Push: Increment top Index and
add the element at top
 Pop : Delete the element at top
and decrement top Index
 Empty: If top Index is -1; Stack is
empty
 int & top( )
QUEUE
 Push: Increment rear Index and
add the element at rear
 Pop : Delete the element at front
and increment front Index
 Empty : If front Index is greater
than rear Index; Queue is empty
 int &front( )
Sikander 3
int main( )
{
int dschoice ,ch , ele;
cout << "1. Stack 2. Queue n";
cin >> dschoice ;
if(dschoice == 1)
{
Stack s1;
for( ; ; ) {
cout <<"StackOperations n";
cout <<"1. Push n 2. Pop 3. Display n";
cin >> ch;
switch(ch) {
case 1 : cout <<"Enter the element to push : ";
cin >> ele;
s1.push(ele);
break;
case 2 : if(s1.empty() == true)
cout <<"Stack is empty n";
else
s1.pop( );
break;
case 3 : s1.display( );
}
}
}
Sikander 4
else
{
Queue q1;
for( ; ; )
{
cout <<"QueueOperations n";
cout <<"1. Push n 2. Pop 3. Display n";
cin >> ch;
switch(ch)
{
case 1 : cout <<"Enter the element to push : ";
cin >> ele;
q1.push(ele);
break;
case 2 : if(q1.empty() == true)
cout <<"Queue is empty n";
else
q1.pop( );
break;
case 3 : q1.display( );
} //End of Switch
} //End of For
} //End of else
} //End of Main
Sikander 5
LDS
Stack Queue
• Stack is a Linear Data Structure
•Queue is a Linear Data Strucuture
class LDS
{
};
Sikander 6
class Stack : public LDS
{
public : void push(int ele);
};
classQueue : public LDS
{
public : void push(int ele);
};
int main( )
{
LDS *ptr = new Stack; //Valid
ptr->push( 5 ); // Invalid; as we don’t have push in LDS
}
class LDS
{
public : virtual void push(int ele);
};
Sikander 7
class Stack : public LDS
{
public : void push(int ele);
};
classQueue : public LDS
{
public : void push(int ele);
};
int main( )
{
LDS *ptr = new Stack; //Valid
ptr->push( 5 ); // No Compilation Error
// Linker Error
}
class LDS
{
public : virtual void push(int ele) = 0;
};
Sikander 8
class Stack : public LDS
{
public : void push(int ele);
};
classQueue : public LDS
{
public : void push(int ele);
};
int main( )
{
LDS *ptr = new Stack; //Valid
ptr->push( 5 ); // No Compilation Error, No Linker Error
//Invokes push of Stack.
ptr = new Queue;
ptr->push(6); //Invokes push of Queue
}
class LDS
{
public: virtual void push(int ) = 0;
virtual void pop( ) = 0;
virtual void display( ) = 0;
virtual bool empty( ) = 0;
};
class Stack : publicLDS
{
public: void push(int ) { cout << “Stack Push n”;}
void pop( ) ;
void display( ) ;
bool empty( ) ;
};
classQueue : public LDS
{
public: void push(int ) { cout << “Queue Push n”;}
void pop( ) ;
void display( ) ;
bool empty( ) ;
};
Sikander 9
int main( )
{
int dschoice ,ch , ele;
LDS *ptr;
cout << "1. Stack 2. Queue n";
cin >> dschoice ;
if(dschoice == 1)
ptr = new Stack;
else
ptr = new Queue;
for( ; ; ) {
cout <<"1. Push n 2. Pop 3. Display n";
cin >> ch;
switch(ch) {
case 1 : cout <<"Enter the element to push : ";
cin >> ele;
ptr->push(ele);
break;
case 2 : if(ptr->empty() == true)
cout <<“Empty n";
else
ptr->pop( );
break;
case 3 : ptr->display( );
}
}
}
void dsoperations(LDS &ref);
int main( )
{
int dschoice ,ch , ele;
LDS *ptr;
Stack s1;
Queue q1;
cout << "1. Stack 2.Queue n";
cin >> dschoice ;
if(dschoice == 1)
dsoperations(s1);
else
dsoperations(q1);
}
Sikander 10
void dsoperations(LDS &ref)
{
for( ; ; ) {
cout <<"1. Push n 2. Pop 3. Display n";
cin >> ch;
switch(ch) {
case 1 : cout <<"Enter the element to push : ";
cin >> ele;
ref.push(ele);
break;
case 2 : if(ref.empty() == true)
cout <<“Empty n";
else
ref.pop( );
break;
case 3 : ref.display( );
}
}
}
class Shape
{ public : virtual int area( ) = 0;
};
class Rectangle : public Shape
{ int m_l , m_b;
public :
Rectangle(int l , int b ) : m_l(l) , m_b(b)
{ }
int area( ){
return m_l * m_b;
}
};
class Circle : public Shape
{ int m_radius;
Public : Circle(int r) : m_radius( r )
{}
int area( )
{
return 3.14 * m_radius * m_radius;
}
}
Sikander 11
int main( )
{
Shape *ps = new Rectangle(4 , 5);
cout << ps->area( );
ps = new Circle(6);
cout << ps->area( );
}
class Shape
{
public : virtual int area( ) = 0;
};
class Rectangle : public Shape
{
int m_l , m_b;
public : Rectangle(int l , int b )
{
m_l = l , m_b = b;
}
int area( ){
return m_l * m_b;
}
};
Sikander 12
int main( )
{
Rectangle r(4 , 5);
Shape &s = r;
s.area( );
}
classA
{
public : virtual void display( ) = 0;
};
voidA::display( )
{
cout <<“A display n”;
}
int main( )
{
}
Sikander 13

More Related Content

What's hot

C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloadingmohamed sikander
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)hhliu
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st StudyChris Ohk
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...ssuserd6b1fd
 
C tech questions
C tech questionsC tech questions
C tech questionsvijay00791
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 

What's hot (20)

Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Implementing string
Implementing stringImplementing string
Implementing string
 
C++ Question on References and Function Overloading
C++ Question on References and Function OverloadingC++ Question on References and Function Overloading
C++ Question on References and Function Overloading
 
C programs
C programsC programs
C programs
 
C questions
C questionsC questions
C questions
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
Array notes
Array notesArray notes
Array notes
 
C program
C programC program
C program
 
C++ file
C++ fileC++ file
C++ file
 
Arrays
ArraysArrays
Arrays
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
C++ TUTORIAL 4
C++ TUTORIAL 4C++ TUTORIAL 4
C++ TUTORIAL 4
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
C++ programs
C++ programsC++ programs
C++ programs
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 4 of 5 by...
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
C tech questions
C tech questionsC tech questions
C tech questions
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 

Viewers also liked

Wamenlu ri melepas team uni papua ke lyon, perancis
Wamenlu ri melepas team uni papua ke lyon, perancisWamenlu ri melepas team uni papua ke lyon, perancis
Wamenlu ri melepas team uni papua ke lyon, perancisUni Papua Football
 
Query tamabhn kode
Query tamabhn kodeQuery tamabhn kode
Query tamabhn kodeferithankyou
 
Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA
Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA
Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA Operator Warnet Vast Raha
 
The DTI business infoload 2016
The DTI business infoload 2016The DTI business infoload 2016
The DTI business infoload 2016Infoload
 
INGENIERIA GEOGRAFICA Y AMBIENTAL
INGENIERIA GEOGRAFICA Y AMBIENTALINGENIERIA GEOGRAFICA Y AMBIENTAL
INGENIERIA GEOGRAFICA Y AMBIENTALMateo47
 
Tugas tipi kegunaan parasetamol
Tugas tipi kegunaan parasetamolTugas tipi kegunaan parasetamol
Tugas tipi kegunaan parasetamolRofiq Nie
 
ИТОГИ УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ И СОРЕВНОВАНИЯХ
 ИТОГИ  УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ  И  СОРЕВНОВАНИЯХ ИТОГИ  УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ  И  СОРЕВНОВАНИЯХ
ИТОГИ УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ И СОРЕВНОВАНИЯХKubasova
 
Standar 22 - Penanganan Perdarahan Postpartum Sekunder
Standar 22 - Penanganan Perdarahan Postpartum SekunderStandar 22 - Penanganan Perdarahan Postpartum Sekunder
Standar 22 - Penanganan Perdarahan Postpartum SekunderAi Ela Ayu Ningsih
 
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...Warnet Raha
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)Akshay soni
 
II Security At Microsoft
II Security At MicrosoftII Security At Microsoft
II Security At MicrosoftMark J. Feldman
 
Benzena Dan Turunannya
Benzena Dan TurunannyaBenzena Dan Turunannya
Benzena Dan TurunannyaRofiq Nie
 
Entertainment industry in india
Entertainment industry in indiaEntertainment industry in india
Entertainment industry in indiaDp Singh
 

Viewers also liked (19)

Wamenlu ri melepas team uni papua ke lyon, perancis
Wamenlu ri melepas team uni papua ke lyon, perancisWamenlu ri melepas team uni papua ke lyon, perancis
Wamenlu ri melepas team uni papua ke lyon, perancis
 
Query tamabhn kode
Query tamabhn kodeQuery tamabhn kode
Query tamabhn kode
 
Hoja de vida
Hoja de vida Hoja de vida
Hoja de vida
 
Telemetry Datasets
Telemetry DatasetsTelemetry Datasets
Telemetry Datasets
 
Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA
Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA
Kti akbid ayu andiani achdania. j 2 AKBID PARAMATA RAHA
 
The DTI business infoload 2016
The DTI business infoload 2016The DTI business infoload 2016
The DTI business infoload 2016
 
INGENIERIA GEOGRAFICA Y AMBIENTAL
INGENIERIA GEOGRAFICA Y AMBIENTALINGENIERIA GEOGRAFICA Y AMBIENTAL
INGENIERIA GEOGRAFICA Y AMBIENTAL
 
Tugas tipi kegunaan parasetamol
Tugas tipi kegunaan parasetamolTugas tipi kegunaan parasetamol
Tugas tipi kegunaan parasetamol
 
ИТОГИ УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ И СОРЕВНОВАНИЯХ
 ИТОГИ  УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ  И  СОРЕВНОВАНИЯХ ИТОГИ  УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ  И  СОРЕВНОВАНИЯХ
ИТОГИ УЧАСТИЯ В ОКРУЖНЫХ И РАЙОННЫХ КОНКУРСАХ И СОРЕВНОВАНИЯХ
 
Stack using Array
Stack using ArrayStack using Array
Stack using Array
 
Standar 22 - Penanganan Perdarahan Postpartum Sekunder
Standar 22 - Penanganan Perdarahan Postpartum SekunderStandar 22 - Penanganan Perdarahan Postpartum Sekunder
Standar 22 - Penanganan Perdarahan Postpartum Sekunder
 
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...
MANAJEMEN DAN PENDOKUMENTASIAN ASUHAN KEBIDANAN IBU NIFAS PADA NY”F” DENGAN A...
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
 
II Security At Microsoft
II Security At MicrosoftII Security At Microsoft
II Security At Microsoft
 
Benzena Dan Turunannya
Benzena Dan TurunannyaBenzena Dan Turunannya
Benzena Dan Turunannya
 
Data Structure (Stack)
Data Structure (Stack)Data Structure (Stack)
Data Structure (Stack)
 
Sop apn
Sop apnSop apn
Sop apn
 
Arrays in java
Arrays in javaArrays in java
Arrays in java
 
Entertainment industry in india
Entertainment industry in indiaEntertainment industry in india
Entertainment industry in india
 

Similar to Polymorphism

Link list part 2
Link list part 2Link list part 2
Link list part 2Anaya Zafar
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdfSOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdfarccreation001
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfforladies
 
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docxAdd functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docxWilliamZnlMarshallc
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++mustkeem khan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diplomamustkeem khan
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanChinmay Chauhan
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applicationsAhsan Mansiv
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 

Similar to Polymorphism (20)

Link list part 2
Link list part 2Link list part 2
Link list part 2
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Stack array
Stack arrayStack array
Stack array
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdfSOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docxAdd functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
Add functions push(int n- Deque &dq) and pop(Deque &dq)- Functions pus.docx
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Lab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdfLab-2.2 717822E504.pdf
Lab-2.2 717822E504.pdf
 
Arrays
ArraysArrays
Arrays
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
week-17x
week-17xweek-17x
week-17x
 
week-18x
week-18xweek-18x
week-18x
 

Recently uploaded

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Eraconfluent
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationJuha-Pekka Tolvanen
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfryanfarris8
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2WSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastPapp Krisztián
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2
 

Recently uploaded (20)

Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Evolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI EraEvolving Data Governance for the Real-time Streaming and AI Era
Evolving Data Governance for the Real-time Streaming and AI Era
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AIWSO2CON 2024 Slides - Unlocking Value with AI
WSO2CON 2024 Slides - Unlocking Value with AI
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdfAzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
AzureNativeQumulo_HPC_Cloud_Native_Benchmarks.pdf
 
Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2Driving Innovation: Scania's API Revolution with WSO2
Driving Innovation: Scania's API Revolution with WSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration ToolingWSO2Con2024 - Low-Code Integration Tooling
WSO2Con2024 - Low-Code Integration Tooling
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 

Polymorphism

  • 2. STACK  void push(int )  void pop( )  bool empty( )  int & top( ) QUEUE  void push(int)  void pop( )  bool empty( )  int &front( ) Sikander 2
  • 3. STACK  Push: Increment top Index and add the element at top  Pop : Delete the element at top and decrement top Index  Empty: If top Index is -1; Stack is empty  int & top( ) QUEUE  Push: Increment rear Index and add the element at rear  Pop : Delete the element at front and increment front Index  Empty : If front Index is greater than rear Index; Queue is empty  int &front( ) Sikander 3
  • 4. int main( ) { int dschoice ,ch , ele; cout << "1. Stack 2. Queue n"; cin >> dschoice ; if(dschoice == 1) { Stack s1; for( ; ; ) { cout <<"StackOperations n"; cout <<"1. Push n 2. Pop 3. Display n"; cin >> ch; switch(ch) { case 1 : cout <<"Enter the element to push : "; cin >> ele; s1.push(ele); break; case 2 : if(s1.empty() == true) cout <<"Stack is empty n"; else s1.pop( ); break; case 3 : s1.display( ); } } } Sikander 4 else { Queue q1; for( ; ; ) { cout <<"QueueOperations n"; cout <<"1. Push n 2. Pop 3. Display n"; cin >> ch; switch(ch) { case 1 : cout <<"Enter the element to push : "; cin >> ele; q1.push(ele); break; case 2 : if(q1.empty() == true) cout <<"Queue is empty n"; else q1.pop( ); break; case 3 : q1.display( ); } //End of Switch } //End of For } //End of else } //End of Main
  • 5. Sikander 5 LDS Stack Queue • Stack is a Linear Data Structure •Queue is a Linear Data Strucuture
  • 6. class LDS { }; Sikander 6 class Stack : public LDS { public : void push(int ele); }; classQueue : public LDS { public : void push(int ele); }; int main( ) { LDS *ptr = new Stack; //Valid ptr->push( 5 ); // Invalid; as we don’t have push in LDS }
  • 7. class LDS { public : virtual void push(int ele); }; Sikander 7 class Stack : public LDS { public : void push(int ele); }; classQueue : public LDS { public : void push(int ele); }; int main( ) { LDS *ptr = new Stack; //Valid ptr->push( 5 ); // No Compilation Error // Linker Error }
  • 8. class LDS { public : virtual void push(int ele) = 0; }; Sikander 8 class Stack : public LDS { public : void push(int ele); }; classQueue : public LDS { public : void push(int ele); }; int main( ) { LDS *ptr = new Stack; //Valid ptr->push( 5 ); // No Compilation Error, No Linker Error //Invokes push of Stack. ptr = new Queue; ptr->push(6); //Invokes push of Queue }
  • 9. class LDS { public: virtual void push(int ) = 0; virtual void pop( ) = 0; virtual void display( ) = 0; virtual bool empty( ) = 0; }; class Stack : publicLDS { public: void push(int ) { cout << “Stack Push n”;} void pop( ) ; void display( ) ; bool empty( ) ; }; classQueue : public LDS { public: void push(int ) { cout << “Queue Push n”;} void pop( ) ; void display( ) ; bool empty( ) ; }; Sikander 9 int main( ) { int dschoice ,ch , ele; LDS *ptr; cout << "1. Stack 2. Queue n"; cin >> dschoice ; if(dschoice == 1) ptr = new Stack; else ptr = new Queue; for( ; ; ) { cout <<"1. Push n 2. Pop 3. Display n"; cin >> ch; switch(ch) { case 1 : cout <<"Enter the element to push : "; cin >> ele; ptr->push(ele); break; case 2 : if(ptr->empty() == true) cout <<“Empty n"; else ptr->pop( ); break; case 3 : ptr->display( ); } } }
  • 10. void dsoperations(LDS &ref); int main( ) { int dschoice ,ch , ele; LDS *ptr; Stack s1; Queue q1; cout << "1. Stack 2.Queue n"; cin >> dschoice ; if(dschoice == 1) dsoperations(s1); else dsoperations(q1); } Sikander 10 void dsoperations(LDS &ref) { for( ; ; ) { cout <<"1. Push n 2. Pop 3. Display n"; cin >> ch; switch(ch) { case 1 : cout <<"Enter the element to push : "; cin >> ele; ref.push(ele); break; case 2 : if(ref.empty() == true) cout <<“Empty n"; else ref.pop( ); break; case 3 : ref.display( ); } } }
  • 11. class Shape { public : virtual int area( ) = 0; }; class Rectangle : public Shape { int m_l , m_b; public : Rectangle(int l , int b ) : m_l(l) , m_b(b) { } int area( ){ return m_l * m_b; } }; class Circle : public Shape { int m_radius; Public : Circle(int r) : m_radius( r ) {} int area( ) { return 3.14 * m_radius * m_radius; } } Sikander 11 int main( ) { Shape *ps = new Rectangle(4 , 5); cout << ps->area( ); ps = new Circle(6); cout << ps->area( ); }
  • 12. class Shape { public : virtual int area( ) = 0; }; class Rectangle : public Shape { int m_l , m_b; public : Rectangle(int l , int b ) { m_l = l , m_b = b; } int area( ){ return m_l * m_b; } }; Sikander 12 int main( ) { Rectangle r(4 , 5); Shape &s = r; s.area( ); }
  • 13. classA { public : virtual void display( ) = 0; }; voidA::display( ) { cout <<“A display n”; } int main( ) { } Sikander 13