SHARE
TWEET

Untitled

a guest Oct 9th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class MyList
  6. {
  7.     public:
  8.         struct element {
  9.             int value;  
  10.             element *next;
  11.         };
  12.        
  13.         element *head;
  14.    
  15.     MyList() {
  16.         head = NULL;
  17.     }                        
  18.    
  19.     void Add(int x) {
  20.         element *temp = new element;    
  21.         temp->value = x;
  22.         temp->next = head;
  23.         head = temp;
  24.     };
  25.    
  26.     void Show() {
  27.         element *temp = head;
  28.    
  29.         while (temp != NULL) {
  30.             cout << temp->value << " ";
  31.             temp = temp->next;
  32.         }
  33.     };                      
  34. };
  35.    
  36.    
  37. int main() {
  38.     MyList list;
  39.    
  40.     list.Add(2);
  41.     list.Add(3);
  42.    
  43.     list.Show();
  44.     return 0;
  45. }
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