Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node
- {
- int data=0;
- Node* next=0;
- };
- void push( Node *head, int n)
- {
- Node *newNode = new Node;
- newNode->data = n;
- newNode->next = 0;
- Node *cur = head;
- while(cur)
- {
- if(cur->next == 0)
- {
- cur->next = newNode;
- return;
- }
- cur = cur->next;
- }
- }
- int pop(struct Node *head)
- {
- int q=0;
- Node *a = head;
- while(a->next)
- {
- a = a->next;
- q++;
- }
- int w = a->data;
- Node *z = head ;
- while(q>1)
- {
- Node* tmpNode;
- tmpNode = head;
- head = tmpNode->next;
- q--;
- }
- delete head->next;
- head->next=0;
- z=head;
- return w ;
- }
- Node* unshift ( Node *head, int n)
- {
- Node *newNode = new Node;
- newNode->data = n;
- newNode->next = head;
- return newNode;
- }
- int shift (Node *&head)
- {
- Node *a;
- int w = head->data;
- a=head->next;
- delete head;
- head=a;
- return w ;
- }
- int main()
- {
- Node* root = new Node;
- root = unshift (root, 10);
- root = unshift (root, 20);
- cout << shift (root)<< endl << endl;
- cout << shift (root)<< endl << endl;
- cout << shift (root)<< endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement