Advertisement
KeiroKamioka

LinkedList

Mar 2nd, 2021
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class node
  6. {
  7.     int value;
  8.     node* next;
  9.  
  10. public:
  11.     node(int value, node* next)
  12.     {
  13.         this->value = value;
  14.         this->next = next;
  15.     }
  16.  
  17.     void print()
  18.     {
  19.         node* current = this;
  20.  
  21.         while (current != nullptr) {
  22.             cout << current->value << " ";
  23.             current = current->next;
  24.         }
  25.     }
  26.  
  27.     //Add the value end at the end of the list (i.e. after the last element)
  28.     void add(int n)
  29.     {
  30.         // Your code starts here
  31.         node* append = NULL;
  32.         append->value = n;
  33.         append->next = NULL;
  34.        
  35.         // Your code ends here    
  36.     }
  37.  
  38.     //Return the sum of all the elements in the list
  39.     int sum()
  40.     {
  41.         // Your code starts here
  42.  
  43.         // Your code ends here    
  44.     }
  45.  
  46.     //Multiplies each element in the list by n
  47.     void mult(int n)
  48.     {
  49.         // Your code starts here
  50.  
  51.         // Your code ends here
  52.     }
  53.  
  54.     //Find the maximum value in the list
  55.     int max()
  56.     {
  57.         // Your code starts here
  58.  
  59.         // Your code ends here    
  60.     }
  61. };
  62.  
  63. //After
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement