SHARE
TWEET

LinkList-bitch example

daniil_mironoff Sep 5th, 2019 (edited) 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct link {
  6.     int data;
  7.     link* next;
  8. };
  9.  
  10. class linklist {
  11.     private:
  12.         link* first;
  13.    
  14.     public:
  15.         linklist() { first = NULL; }
  16.    
  17.         ~linklist() {
  18.             while(first) {
  19.                 link* temp = first -> next;
  20.                 delete first;
  21.                 first = temp;
  22.                
  23. //                cout << "Удален объект!" << endl;
  24.             }
  25.        }
  26.    
  27.         void additem(int d) {
  28.             link* newlink = new link;
  29.             newlink -> data = d;
  30.             newlink -> next = first;
  31.             first = newlink;
  32.         }
  33.    
  34.         void display() {
  35.             link* temp = first;
  36.            
  37.             while(temp) {
  38.                 cout << temp -> data << endl;
  39.                 temp = temp -> next;
  40.             }
  41.         }
  42. };
  43.  
  44. int main() {
  45.     linklist obj;
  46.     obj.additem(22);
  47.     obj.additem(11);
  48.     obj.additem(44);
  49.     obj.additem(77);
  50.     obj.additem(33);
  51.    
  52.     obj.display();
  53.    
  54.     return 0;
  55. }
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