Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- struct Node
- {
- int data;
- struct Node* next;
- };
- Node* head = NULL;
- void push(int x)
- {
- Node *t = (struct Node*)malloc(sizeof(struct Node));
- t->data = x;
- t->next = head;
- head = t;
- };
- void Display(struct Node *p)
- {
- while(p!=NULL)
- {
- cout << p->data << endl;
- p = p->next;
- }
- }
- void pop(int n)
- {
- for(int i =0; i<n; i++)
- {
- Node *t = (struct Node*)malloc(sizeof(struct Node));
- t = head;
- head = head -> next;
- delete t;
- }
- }
- int main()
- {
- push(10); push(0);
- Display(head);
- pop(1);
- Display(head);
- }
Advertisement
RAW Paste Data
Copied
Advertisement