Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node
- {
- int data;
- Node *point;
- };
- Node *head;
- Node* getnewnode(int value)
- {
- Node *newnode = new Node();
- newnode -> data = value;
- newnode -> point = NULL;
- return newnode;
- }
- void Push(int value, int limit)
- {
- int Count = 1;
- Node *temp = head;
- while(temp != NULL)
- {
- Count++;
- temp = temp->point;
- }
- if(Count <= limit)
- {
- Node *newnode = getnewnode(value);
- newnode -> point = head;
- head = newnode;
- }
- else
- {
- cout << "\nStack Over Flow\n" <<endl;
- }
- }
- void Pop()
- {
- if(head==NULL)
- {
- cout << "\nStack Empty\n" <<endl;
- return;
- }
- Node *temp = head;
- head = temp->point;
- delete temp;
- }
- void print()
- {
- Node *temp = head;
- cout << "Current Link List data...." <<endl;
- while(temp != NULL)
- {
- cout << temp->data << " ";
- temp = temp->point;
- }
- cout <<endl;
- }
- int main()
- {
- int limit;
- limit = 4;
- cout << "Stack limit 4\n" <<endl;
- Push(10,limit);
- print();
- Push(20,limit);
- print();
- Push(30,limit);
- print();
- Push(40,limit);
- print();
- Push(50,limit);// Stack will over flow
- Pop();
- print();
- Pop();
- print();
- Pop();
- print();
- Pop();
- print();
- Pop(); // Stack Empty Nothing to pop
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement