SlideShare a Scribd company logo
1 of 14
Download to read offline
//later we create a specialstack class ,which inherits from stack class.there we return the smallest
integer
//implementation
#include
#include
using namespace std;
/* A simple stack class named IntStack with push and pop operations */
class IntStack
{
private:
static const int max = 100;
int arr[max];
int top;
public:
//constructor for initialising value of top
IntStack()
{
top = -1;
}
void push(int x);
int pop();
bool isEmpty();
bool isFull();
};
/* Stack's member method to check if the stack is iempty */
bool IntStack::isEmpty()
{
if(top == -1)
return true;
return false;
}
/* Stack's member method to check if the stack is full */
bool IntStack::isFull()
{
if(top == max - 1)
return true;
return false;
}
/* Stack's member method push() to insert an element */
void IntStack::push(int x)
{
if(isFull())
{
cout<<"Stack Overflow";
}
top++;
arr[top] = x;
}
/* Stack's member method pop() to remove an element from it */
int IntStack::pop()
{
if(isEmpty())
{
cout<<"Stack Underflow";
abort();
}
int x = arr[top];
top--;
return x;
}
/* A class that supports all the stack operations and one additional operation getMIN() that
returns the minimum element from stack at any time. This class inherits from the stack class and
uses an auxiliarry stack that holds minimum elements */
class SpecialStack: public IntStack
{
IntStack min;
public:
//function declarations
void push(int x);
int pop();
int getMIN();
};
/* SpecialStack's member method to insert an element to it. This method
makes sure that the min stack is also updated with appropriate minimum
values */
void SpecialStack::push(int x)
{
if(isEmpty()==true)
{
IntStack::push(x);
min.push(x);
}
else
{
IntStack::push(x);
int y = min.pop();
min.push(y);
/* push only when the incoming element of main stack is smaller
than or equal to top of auxiliary stack */
if( x <= y )
min.push(x);
}
}
/* SpecialStack's member method to remove an element from it. This method
removes top element from min stack also. */
int SpecialStack::pop()
{
int x = IntStack::pop();
int y = min.pop();
/* Push the popped element y back only if it is not equal to x */
if ( y != x )
min.push(y);
return x;
}
/* SpecialStack's member method to get minimum element from it. */
int SpecialStack::getMIN()
{
int x = min.pop();
min.push(x);
return x;
}
/* main program to test SpecialStack methods */
//execution starts here
int main()
{
SpecialStack s;
//push 3 elements and get the minimum
s.push(15);
s.push(25);
s.push(33);
cout<
#include
using namespace std;
/* A simple stack class named IntStack with push and pop operations */
class IntStack
{
private:
static const int max = 100;
int arr[max];
int top;
public:
//constructor for initialising value of top
IntStack()
{
top = -1;
}
void push(int x);
int pop();
bool isEmpty();
bool isFull();
};
/* Stack's member method to check if the stack is iempty */
bool IntStack::isEmpty()
{
if(top == -1)
return true;
return false;
}
/* Stack's member method to check if the stack is full */
bool IntStack::isFull()
{
if(top == max - 1)
return true;
return false;
}
/* Stack's member method push() to insert an element */
void IntStack::push(int x)
{
if(isFull())
{
cout<<"Stack Overflow";
}
top++;
arr[top] = x;
}
/* Stack's member method pop() to remove an element from it */
int IntStack::pop()
{
if(isEmpty())
{
cout<<"Stack Underflow";
abort();
}
int x = arr[top];
top--;
return x;
}
/* A class that supports all the stack operations and one additional operation getMIN() that
returns the minimum element from stack at any time. This class inherits from the stack class and
uses an auxiliarry stack that holds minimum elements */
class SpecialStack: public IntStack
{
IntStack min;
public:
//function declarations
void push(int x);
int pop();
int getMIN();
};
/* SpecialStack's member method to insert an element to it. This method
makes sure that the min stack is also updated with appropriate minimum
values */
void SpecialStack::push(int x)
{
if(isEmpty()==true)
{
IntStack::push(x);
min.push(x);
}
else
{
IntStack::push(x);
int y = min.pop();
min.push(y);
/* push only when the incoming element of main stack is smaller
than or equal to top of auxiliary stack */
if( x <= y )
min.push(x);
}
}
/* SpecialStack's member method to remove an element from it. This method
removes top element from min stack also. */
int SpecialStack::pop()
{
int x = IntStack::pop();
int y = min.pop();
/* Push the popped element y back only if it is not equal to x */
if ( y != x )
min.push(y);
return x;
}
/* SpecialStack's member method to get minimum element from it. */
int SpecialStack::getMIN()
{
int x = min.pop();
min.push(x);
return x;
}
/* main program to test SpecialStack methods */
//execution starts here
int main()
{
SpecialStack s;
//push 3 elements and get the minimum
s.push(15);
s.push(25);
s.push(33);
cout<
Solution
//later we create a specialstack class ,which inherits from stack class.there we return the smallest
integer
//implementation
#include
#include
using namespace std;
/* A simple stack class named IntStack with push and pop operations */
class IntStack
{
private:
static const int max = 100;
int arr[max];
int top;
public:
//constructor for initialising value of top
IntStack()
{
top = -1;
}
void push(int x);
int pop();
bool isEmpty();
bool isFull();
};
/* Stack's member method to check if the stack is iempty */
bool IntStack::isEmpty()
{
if(top == -1)
return true;
return false;
}
/* Stack's member method to check if the stack is full */
bool IntStack::isFull()
{
if(top == max - 1)
return true;
return false;
}
/* Stack's member method push() to insert an element */
void IntStack::push(int x)
{
if(isFull())
{
cout<<"Stack Overflow";
}
top++;
arr[top] = x;
}
/* Stack's member method pop() to remove an element from it */
int IntStack::pop()
{
if(isEmpty())
{
cout<<"Stack Underflow";
abort();
}
int x = arr[top];
top--;
return x;
}
/* A class that supports all the stack operations and one additional operation getMIN() that
returns the minimum element from stack at any time. This class inherits from the stack class and
uses an auxiliarry stack that holds minimum elements */
class SpecialStack: public IntStack
{
IntStack min;
public:
//function declarations
void push(int x);
int pop();
int getMIN();
};
/* SpecialStack's member method to insert an element to it. This method
makes sure that the min stack is also updated with appropriate minimum
values */
void SpecialStack::push(int x)
{
if(isEmpty()==true)
{
IntStack::push(x);
min.push(x);
}
else
{
IntStack::push(x);
int y = min.pop();
min.push(y);
/* push only when the incoming element of main stack is smaller
than or equal to top of auxiliary stack */
if( x <= y )
min.push(x);
}
}
/* SpecialStack's member method to remove an element from it. This method
removes top element from min stack also. */
int SpecialStack::pop()
{
int x = IntStack::pop();
int y = min.pop();
/* Push the popped element y back only if it is not equal to x */
if ( y != x )
min.push(y);
return x;
}
/* SpecialStack's member method to get minimum element from it. */
int SpecialStack::getMIN()
{
int x = min.pop();
min.push(x);
return x;
}
/* main program to test SpecialStack methods */
//execution starts here
int main()
{
SpecialStack s;
//push 3 elements and get the minimum
s.push(15);
s.push(25);
s.push(33);
cout<
#include
using namespace std;
/* A simple stack class named IntStack with push and pop operations */
class IntStack
{
private:
static const int max = 100;
int arr[max];
int top;
public:
//constructor for initialising value of top
IntStack()
{
top = -1;
}
void push(int x);
int pop();
bool isEmpty();
bool isFull();
};
/* Stack's member method to check if the stack is iempty */
bool IntStack::isEmpty()
{
if(top == -1)
return true;
return false;
}
/* Stack's member method to check if the stack is full */
bool IntStack::isFull()
{
if(top == max - 1)
return true;
return false;
}
/* Stack's member method push() to insert an element */
void IntStack::push(int x)
{
if(isFull())
{
cout<<"Stack Overflow";
}
top++;
arr[top] = x;
}
/* Stack's member method pop() to remove an element from it */
int IntStack::pop()
{
if(isEmpty())
{
cout<<"Stack Underflow";
abort();
}
int x = arr[top];
top--;
return x;
}
/* A class that supports all the stack operations and one additional operation getMIN() that
returns the minimum element from stack at any time. This class inherits from the stack class and
uses an auxiliarry stack that holds minimum elements */
class SpecialStack: public IntStack
{
IntStack min;
public:
//function declarations
void push(int x);
int pop();
int getMIN();
};
/* SpecialStack's member method to insert an element to it. This method
makes sure that the min stack is also updated with appropriate minimum
values */
void SpecialStack::push(int x)
{
if(isEmpty()==true)
{
IntStack::push(x);
min.push(x);
}
else
{
IntStack::push(x);
int y = min.pop();
min.push(y);
/* push only when the incoming element of main stack is smaller
than or equal to top of auxiliary stack */
if( x <= y )
min.push(x);
}
}
/* SpecialStack's member method to remove an element from it. This method
removes top element from min stack also. */
int SpecialStack::pop()
{
int x = IntStack::pop();
int y = min.pop();
/* Push the popped element y back only if it is not equal to x */
if ( y != x )
min.push(y);
return x;
}
/* SpecialStack's member method to get minimum element from it. */
int SpecialStack::getMIN()
{
int x = min.pop();
min.push(x);
return x;
}
/* main program to test SpecialStack methods */
//execution starts here
int main()
{
SpecialStack s;
//push 3 elements and get the minimum
s.push(15);
s.push(25);
s.push(33);
cout<

More Related Content

Similar to later we create a specialstack class ,which inherits from stack cl.pdf

(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manualChandrapriya Jayabal
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfSIGMATAX1
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdffathimafancyjeweller
 
Need help with writing the test cases for the following code in java-.docx
Need help with writing the test cases for the following code in java-.docxNeed help with writing the test cases for the following code in java-.docx
Need help with writing the test cases for the following code in java-.docxLucasmHKChapmant
 
C program for array implementation of stack#include stdio.h.pdf
 C program for array implementation of stack#include stdio.h.pdf C program for array implementation of stack#include stdio.h.pdf
C program for array implementation of stack#include stdio.h.pdfmohammadirfan136964
 
#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdfasif1401
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacksmaamir farooq
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docxVictorXUQGloverl
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applicationsAhsan Mansiv
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
All code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdfAll code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdfakashenterprises93
 

Similar to later we create a specialstack class ,which inherits from stack cl.pdf (20)

(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual(674335607) cs2309 java-lab-manual
(674335607) cs2309 java-lab-manual
 
Implement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdfImplement the ADT stack by using an array stack to contain its entri.pdf
Implement the ADT stack by using an array stack to contain its entri.pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 
Need help with writing the test cases for the following code in java-.docx
Need help with writing the test cases for the following code in java-.docxNeed help with writing the test cases for the following code in java-.docx
Need help with writing the test cases for the following code in java-.docx
 
C program for array implementation of stack#include stdio.h.pdf
 C program for array implementation of stack#include stdio.h.pdf C program for array implementation of stack#include stdio.h.pdf
C program for array implementation of stack#include stdio.h.pdf
 
#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf#includeiostream#includestdlib.husing namespace std;class .pdf
#includeiostream#includestdlib.husing namespace std;class .pdf
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Stack queue
Stack queueStack queue
Stack queue
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
 
Stack and its applications
Stack and its applicationsStack and its applications
Stack and its applications
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
All code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdfAll code should be in C++Using the UnsortedList class (UnsortedLis.pdf
All code should be in C++Using the UnsortedList class (UnsortedLis.pdf
 
Algo>Stacks
Algo>StacksAlgo>Stacks
Algo>Stacks
 

More from anandhomeneeds

Driver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfDriver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfanandhomeneeds
 
Question 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfQuestion 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfanandhomeneeds
 
The answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdfThe answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdfanandhomeneeds
 
HiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdfHiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdfanandhomeneeds
 
What property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdfWhat property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdfanandhomeneeds
 
upload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdfupload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdfanandhomeneeds
 
the phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdfthe phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdfanandhomeneeds
 
The substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdfThe substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdfanandhomeneeds
 
I think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdfI think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdfanandhomeneeds
 
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdfD(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdfanandhomeneeds
 
1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdf1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdfanandhomeneeds
 
Answer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdfAnswer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdfanandhomeneeds
 
The key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdfThe key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdfanandhomeneeds
 
Properties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdfProperties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdfanandhomeneeds
 
MgCO3 Increasing acidity will cause the following reaction Mg.pdf
 MgCO3 Increasing acidity will cause the following reaction Mg.pdf MgCO3 Increasing acidity will cause the following reaction Mg.pdf
MgCO3 Increasing acidity will cause the following reaction Mg.pdfanandhomeneeds
 
Environmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdfEnvironmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdfanandhomeneeds
 
1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdf1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdfanandhomeneeds
 
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdfMobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdfanandhomeneeds
 
Answer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdfAnswer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdfanandhomeneeds
 
3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdf3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdfanandhomeneeds
 

More from anandhomeneeds (20)

Driver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfDriver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdf
 
Question 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdfQuestion 1,2,4 ------------------------------------Please check.pdf
Question 1,2,4 ------------------------------------Please check.pdf
 
The answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdfThe answer is C. securin.APC degrade securin to release separase .pdf
The answer is C. securin.APC degrade securin to release separase .pdf
 
HiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdfHiCan you please summarise the question. More information confuse .pdf
HiCan you please summarise the question. More information confuse .pdf
 
What property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdfWhat property of proteins us used to separate them in HICHydrophob.pdf
What property of proteins us used to separate them in HICHydrophob.pdf
 
upload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdfupload complete priblem somthing is missingSolutionupload comp.pdf
upload complete priblem somthing is missingSolutionupload comp.pdf
 
the phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdfthe phenomena responsible for this type of inheritancce is Epistasis.pdf
the phenomena responsible for this type of inheritancce is Epistasis.pdf
 
The substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdfThe substrate in urease test is urea.The end products in urease te.pdf
The substrate in urease test is urea.The end products in urease te.pdf
 
I think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdfI think that 34SolutionI think that 34.pdf
I think that 34SolutionI think that 34.pdf
 
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdfD(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
D(ANSWER)Polycrystalline or multicrystalline materials, or polycry.pdf
 
1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdf1.It is the process of directing the television assistances are tran.pdf
1.It is the process of directing the television assistances are tran.pdf
 
Answer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdfAnswer The major objective of implementing a health information man.pdf
Answer The major objective of implementing a health information man.pdf
 
The key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdfThe key assumptions made by the Hadoop Distributed File System(HDFS).pdf
The key assumptions made by the Hadoop Distributed File System(HDFS).pdf
 
Properties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdfProperties areMeanModeMedianQuartilesPercentilesRan.pdf
Properties areMeanModeMedianQuartilesPercentilesRan.pdf
 
MgCO3 Increasing acidity will cause the following reaction Mg.pdf
 MgCO3 Increasing acidity will cause the following reaction Mg.pdf MgCO3 Increasing acidity will cause the following reaction Mg.pdf
MgCO3 Increasing acidity will cause the following reaction Mg.pdf
 
Environmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdfEnvironmental conditions play a key role in defining the function an.pdf
Environmental conditions play a key role in defining the function an.pdf
 
1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdf1. Autralopith is a known genus of hominids which is extinct today..pdf
1. Autralopith is a known genus of hominids which is extinct today..pdf
 
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdfMobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
Mobile IP1) Mobile IP(MIP) is an Internet Engineering Task Force(.pdf
 
Answer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdfAnswer1. Cells can generate many different tissue types endoderm,.pdf
Answer1. Cells can generate many different tissue types endoderm,.pdf
 
3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdf3 a) The trace of an nSolution3 a) The trace of an n.pdf
3 a) The trace of an nSolution3 a) The trace of an n.pdf
 

Recently uploaded

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 

Recently uploaded (20)

Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 

later we create a specialstack class ,which inherits from stack cl.pdf

  • 1. //later we create a specialstack class ,which inherits from stack class.there we return the smallest integer //implementation #include #include using namespace std; /* A simple stack class named IntStack with push and pop operations */ class IntStack { private: static const int max = 100; int arr[max]; int top; public: //constructor for initialising value of top IntStack() { top = -1; } void push(int x); int pop(); bool isEmpty(); bool isFull(); }; /* Stack's member method to check if the stack is iempty */ bool IntStack::isEmpty() { if(top == -1) return true; return false; } /* Stack's member method to check if the stack is full */ bool IntStack::isFull() { if(top == max - 1)
  • 2. return true; return false; } /* Stack's member method push() to insert an element */ void IntStack::push(int x) { if(isFull()) { cout<<"Stack Overflow"; } top++; arr[top] = x; } /* Stack's member method pop() to remove an element from it */ int IntStack::pop() { if(isEmpty()) { cout<<"Stack Underflow"; abort(); } int x = arr[top]; top--; return x; } /* A class that supports all the stack operations and one additional operation getMIN() that returns the minimum element from stack at any time. This class inherits from the stack class and uses an auxiliarry stack that holds minimum elements */ class SpecialStack: public IntStack { IntStack min; public: //function declarations void push(int x); int pop(); int getMIN();
  • 3. }; /* SpecialStack's member method to insert an element to it. This method makes sure that the min stack is also updated with appropriate minimum values */ void SpecialStack::push(int x) { if(isEmpty()==true) { IntStack::push(x); min.push(x); } else { IntStack::push(x); int y = min.pop(); min.push(y); /* push only when the incoming element of main stack is smaller than or equal to top of auxiliary stack */ if( x <= y ) min.push(x); } } /* SpecialStack's member method to remove an element from it. This method removes top element from min stack also. */ int SpecialStack::pop() { int x = IntStack::pop(); int y = min.pop(); /* Push the popped element y back only if it is not equal to x */ if ( y != x ) min.push(y); return x; } /* SpecialStack's member method to get minimum element from it. */ int SpecialStack::getMIN()
  • 4. { int x = min.pop(); min.push(x); return x; } /* main program to test SpecialStack methods */ //execution starts here int main() { SpecialStack s; //push 3 elements and get the minimum s.push(15); s.push(25); s.push(33); cout< #include using namespace std; /* A simple stack class named IntStack with push and pop operations */ class IntStack { private: static const int max = 100; int arr[max]; int top; public: //constructor for initialising value of top IntStack() { top = -1; } void push(int x); int pop(); bool isEmpty(); bool isFull(); };
  • 5. /* Stack's member method to check if the stack is iempty */ bool IntStack::isEmpty() { if(top == -1) return true; return false; } /* Stack's member method to check if the stack is full */ bool IntStack::isFull() { if(top == max - 1) return true; return false; } /* Stack's member method push() to insert an element */ void IntStack::push(int x) { if(isFull()) { cout<<"Stack Overflow"; } top++; arr[top] = x; } /* Stack's member method pop() to remove an element from it */ int IntStack::pop() { if(isEmpty()) { cout<<"Stack Underflow"; abort(); } int x = arr[top]; top--; return x; }
  • 6. /* A class that supports all the stack operations and one additional operation getMIN() that returns the minimum element from stack at any time. This class inherits from the stack class and uses an auxiliarry stack that holds minimum elements */ class SpecialStack: public IntStack { IntStack min; public: //function declarations void push(int x); int pop(); int getMIN(); }; /* SpecialStack's member method to insert an element to it. This method makes sure that the min stack is also updated with appropriate minimum values */ void SpecialStack::push(int x) { if(isEmpty()==true) { IntStack::push(x); min.push(x); } else { IntStack::push(x); int y = min.pop(); min.push(y); /* push only when the incoming element of main stack is smaller than or equal to top of auxiliary stack */ if( x <= y ) min.push(x); } } /* SpecialStack's member method to remove an element from it. This method removes top element from min stack also. */
  • 7. int SpecialStack::pop() { int x = IntStack::pop(); int y = min.pop(); /* Push the popped element y back only if it is not equal to x */ if ( y != x ) min.push(y); return x; } /* SpecialStack's member method to get minimum element from it. */ int SpecialStack::getMIN() { int x = min.pop(); min.push(x); return x; } /* main program to test SpecialStack methods */ //execution starts here int main() { SpecialStack s; //push 3 elements and get the minimum s.push(15); s.push(25); s.push(33); cout< Solution //later we create a specialstack class ,which inherits from stack class.there we return the smallest integer //implementation #include #include using namespace std; /* A simple stack class named IntStack with push and pop operations */
  • 8. class IntStack { private: static const int max = 100; int arr[max]; int top; public: //constructor for initialising value of top IntStack() { top = -1; } void push(int x); int pop(); bool isEmpty(); bool isFull(); }; /* Stack's member method to check if the stack is iempty */ bool IntStack::isEmpty() { if(top == -1) return true; return false; } /* Stack's member method to check if the stack is full */ bool IntStack::isFull() { if(top == max - 1) return true; return false; } /* Stack's member method push() to insert an element */ void IntStack::push(int x) { if(isFull()) {
  • 9. cout<<"Stack Overflow"; } top++; arr[top] = x; } /* Stack's member method pop() to remove an element from it */ int IntStack::pop() { if(isEmpty()) { cout<<"Stack Underflow"; abort(); } int x = arr[top]; top--; return x; } /* A class that supports all the stack operations and one additional operation getMIN() that returns the minimum element from stack at any time. This class inherits from the stack class and uses an auxiliarry stack that holds minimum elements */ class SpecialStack: public IntStack { IntStack min; public: //function declarations void push(int x); int pop(); int getMIN(); }; /* SpecialStack's member method to insert an element to it. This method makes sure that the min stack is also updated with appropriate minimum values */ void SpecialStack::push(int x) { if(isEmpty()==true) {
  • 10. IntStack::push(x); min.push(x); } else { IntStack::push(x); int y = min.pop(); min.push(y); /* push only when the incoming element of main stack is smaller than or equal to top of auxiliary stack */ if( x <= y ) min.push(x); } } /* SpecialStack's member method to remove an element from it. This method removes top element from min stack also. */ int SpecialStack::pop() { int x = IntStack::pop(); int y = min.pop(); /* Push the popped element y back only if it is not equal to x */ if ( y != x ) min.push(y); return x; } /* SpecialStack's member method to get minimum element from it. */ int SpecialStack::getMIN() { int x = min.pop(); min.push(x); return x; } /* main program to test SpecialStack methods */ //execution starts here
  • 11. int main() { SpecialStack s; //push 3 elements and get the minimum s.push(15); s.push(25); s.push(33); cout< #include using namespace std; /* A simple stack class named IntStack with push and pop operations */ class IntStack { private: static const int max = 100; int arr[max]; int top; public: //constructor for initialising value of top IntStack() { top = -1; } void push(int x); int pop(); bool isEmpty(); bool isFull(); }; /* Stack's member method to check if the stack is iempty */ bool IntStack::isEmpty() { if(top == -1) return true; return false; } /* Stack's member method to check if the stack is full */
  • 12. bool IntStack::isFull() { if(top == max - 1) return true; return false; } /* Stack's member method push() to insert an element */ void IntStack::push(int x) { if(isFull()) { cout<<"Stack Overflow"; } top++; arr[top] = x; } /* Stack's member method pop() to remove an element from it */ int IntStack::pop() { if(isEmpty()) { cout<<"Stack Underflow"; abort(); } int x = arr[top]; top--; return x; } /* A class that supports all the stack operations and one additional operation getMIN() that returns the minimum element from stack at any time. This class inherits from the stack class and uses an auxiliarry stack that holds minimum elements */ class SpecialStack: public IntStack { IntStack min; public: //function declarations
  • 13. void push(int x); int pop(); int getMIN(); }; /* SpecialStack's member method to insert an element to it. This method makes sure that the min stack is also updated with appropriate minimum values */ void SpecialStack::push(int x) { if(isEmpty()==true) { IntStack::push(x); min.push(x); } else { IntStack::push(x); int y = min.pop(); min.push(y); /* push only when the incoming element of main stack is smaller than or equal to top of auxiliary stack */ if( x <= y ) min.push(x); } } /* SpecialStack's member method to remove an element from it. This method removes top element from min stack also. */ int SpecialStack::pop() { int x = IntStack::pop(); int y = min.pop(); /* Push the popped element y back only if it is not equal to x */ if ( y != x ) min.push(y); return x;
  • 14. } /* SpecialStack's member method to get minimum element from it. */ int SpecialStack::getMIN() { int x = min.pop(); min.push(x); return x; } /* main program to test SpecialStack methods */ //execution starts here int main() { SpecialStack s; //push 3 elements and get the minimum s.push(15); s.push(25); s.push(33); cout<