Skip to content

Instantly share code, notes, and snippets.

@zainulhasan
Created August 3, 2015 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zainulhasan/47b1bfde1542a2bad42c to your computer and use it in GitHub Desktop.
Save zainulhasan/47b1bfde1542a2bad42c to your computer and use it in GitHub Desktop.
/******************************
Dstack.cpp
Auther:Syed Zain Ul hasan
*****************************/
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
};
class Dstack
{
private:
Node *top;
public:
Dstack()
{
top = NULL;
}
void push(int data)
{
Node *tmp;
tmp=new Node();
tmp->data = data;
tmp->next = top;
top = tmp;
}
void pop(){
if(top!=NULL){
Node *tmp =top;
top=tmp->next;
delete tmp;
}else {
cout<<"Stacks Underflow"<<endl;
}
}
void display(){
Node * tmp=top;
while(tmp->next!=NULL){
cout<<tmp->data<<" ";
tmp=tmp->next;
}
}
};
int main(int argc, char** argv)
{
Dstack ds;
ds.push(104);
ds.push(566);
ds.push(105);
ds.push(5644);
ds.push(200);
ds.push(5600);
ds.push(100);
ds.push(5622);
ds.display();
cout<<endl;
ds.pop();
ds.pop();
ds.pop();
ds.display();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment