Advertisement
_Kripaka001_

linkedList 8

Aug 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  class List{
  6.     public:
  7.  
  8.         List(){ next = NULL; data = 0;}
  9.         int data;
  10.         List* next;
  11.  };
  12.  
  13. void output (List* root){
  14.    List node = new List();
  15.    while(root != NULL){
  16.         cout << root->data << " ";
  17.         root = root->next;
  18.    }
  19.    cout << endl;
  20. }
  21.  
  22.  void push (List*& root, int value){     // insert line to the end ||-||-|new|
  23.     List *node = new List();
  24.     node->data = value;
  25.     node->next = root;
  26.     root = node;
  27.     //output(root);
  28.     //delete node;
  29. }
  30.  
  31.  int main(){
  32.     List* root = new List();
  33.     push(root, 10);
  34.     cout << root->data;
  35.     push(root, 20);
  36.     cout << root->data << " ";
  37.     output(root);
  38.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement