Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- struct Node
- {
- int data;
- Node* next;
- };
- Node* tos = NULL;
- void isEmpty();
- void push(int x);
- void pop();
- void top();
- int main(){
- isEmpty();
- push(1);
- push(2);
- top();
- pop();
- isEmpty();
- top();
- return 0;
- }
- void isEmpty(){
- if(tos==NULL){
- cout <<"Stack is empty"<<endl;
- return;
- }
- cout <<"Stack is not empty"<<endl;
- }
- void push(int x){
- Node* temp = new Node();
- temp->data = x;
- temp->next = tos;
- tos = temp;
- }
- void pop(){
- if(tos==NULL){
- cout <<"Stack is empty"<<endl;
- return;
- }
- Node* del = tos;
- tos = tos->next;
- delete del;
- }
- void top(){
- if(tos==NULL){
- cout <<"Stack is empty"<<endl;
- return;
- }
- cout << tos->data << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement