#include<iostream.h>
#include<conio.h>
template<class T>
class stack
{
private:
T* stk;
int top;
int size;
public:
stack(int);
stack()
{
delete[] stk;
}
int push(const T&);
int pop(T&);
int empty()const
{
return (top == -1);
}
int full() const
{
return top == (size -1);
}
}; // End of class template
template<class T> // constructor
stack<T> :: stack(int sz)
{
size = sz;
str = new T(size);
top = -1;
}
template <class T> // pushing an element onto the stack
int stack <T> :: push (const T& element)
{
if (!full())
{
top = top +1;
stk[top] = element;
return 1;
}
else
return 0;
}
template <class T>
int stack <T> :: pop (T& item)
{
if (!empty())
{
item = stk[top];
top = top -1;
return 1;
else
return 0;
}
}
//main program
int main()
{
stack<int>intstk(5);// instantiation of class template for type int
stack <float>fltstk(5);//instantiation of class template for type float
int ival = 12;
clrscr();
float fval = 5.3;
cout<<"Working of integer stack ";
cout<<endl;
cout<<"Start pushing values onto the stack ";
cout<<endl;
while (intstk.push (ival))
{
cout<<ival<<endl;
ival = ival +10;
}
cout<<"Stack is full : You cannot push more ";
cout<<endl;
cout<<"Now pop all the elements one by one ";
cout<<endl;
{
cout<<ival <<"is deleted" <<endl;
}
cout<<"Stack is empty. You cannot delete further !!";
cout<<endl;
cout<< "Working of stack with floating-point numbers";
cout<<endl;
while (fltstk.push(fval))
{
cout <<fval <<endl;
fval = fval + 3.5;
}
cout<< "Stack is full : You cannot add more ! "<<endl;
cout<<"Now, Pop all elements ";
cout<<endl;
while()
{
cout<<fval<<"is deleted";
cout<<endl;
}
cout<<"Stack is empty : You cannot delete further !!"<<endl;
getch();
return 0;
} // End of main
Home       |      About Us       |     Portfolio       |      Services       |       Career        |    Contact Us       |      Industrial Training        |      Achievement 
Corporate Services
  Web Design and development
  Web Promotion (SEO)
  Multimedia/CD Presentation
  Software development

  E.Commerce

Training@balujalabs

  Software Courses
  Hardware Courses
  Networking.Courses
  Mobile Repairing Courses
  UGC Degrees
Student Corner
 Programming & Projects
 Placement Papers
 Project Ideas
 Synopsis Ideas

  Franchise Section

 Administrator
Franchise Inquiry
 
 

This process is to define and declare a class template for stack. A stack is a data structure in which all insertions and deletions are made at the same end called top insertions are called push operations while deletions are referred to as pop operations.

 

 

 

 

 

 

 

 

 

                                                                                                                                          

1 This program illustrates the definition and declaration of a class template for accepting two numbers and finding their sum.
2 This process is to define and declare a class template for stack. A stack is a data structure in which all insertions and deletions are made at the same end called top insertions are called push operations while deletions are referred to as pop operations.
3 This program is to create a template class Queue, with add and delete member functions. And, using this class template, a queue of integers and doubles is implemented.
4 This program illustrates the static data members of class templates.

 

     
Home       |      About Us       |     Portfolio       |      Services       |       Career        |    Contact Us       |      Industrial Training        |      Achievement