SHARE
TWEET

Untitled

a guest Oct 21st, 2019 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct node {
  5.     node * next;
  6.     int data;
  7. };
  8.  
  9. void push(node * List, int x) {
  10.     node * temp = new node;
  11.    
  12.     temp->next = NULL;
  13.     temp->data = x;
  14.    
  15.     node * tempList = List;
  16.     while (1) {
  17.         if (tempList->next == NULL) break;
  18.         tempList = tempList->next;
  19.     }
  20.    
  21.     tempList->next = temp;
  22. }
  23.  
  24. void pop(node * List) {
  25.    
  26.     node * tempList = List;
  27.     while (1) {
  28.         node * tempNode = tempList->next;
  29.         if (tempNode->next == NULL) break;
  30.         tempList = tempList->next;
  31.     }
  32.    
  33.     tempList->next = NULL;
  34. }
  35.  
  36. int main () {
  37.    
  38.     node * List = new node;
  39.     List->next = NULL;
  40.     List->data = 2;
  41.     push(List, 3);
  42.     push(List, -1);
  43.     pop(List);
  44.    
  45.     ///node * tempNode = List->next;
  46.     //cout << tempNode->data << endl;
  47.    
  48.     node * temp = List;
  49.     while (1) {
  50.         cout << temp->data << endl;
  51.        
  52.         if (temp->next == NULL) break;
  53.         temp = temp->next;
  54.     }
  55.    
  56.     return 0;
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top