G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 7th, 2020 200 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <Windows.h>
  3.  
  4. using namespace std;
  5.  
  6. class List
  7. {
  8. public:
  9.  
  10.     List()
  11.     {
  12.         Head = new Node();
  13.     }
  14.  
  15.     ~List()
  16.     {
  17.         delete Head;
  18.     }
  19.  
  20.     void add(INT value)
  21.     {
  22.         Node* tmp = new Node(value, Head);
  23.         Head = tmp;
  24.     }
  25.  
  26.     void copy(const List& other)
  27.     {
  28.         delete this->Head;
  29.         Head = new Node(other.Head->value);
  30.  
  31.         Node* src = this->Head;
  32.         Node* dst = other.Head->next;
  33.  
  34.         while (dst->next)
  35.         {
  36.             src->next = new Node(dst->value);
  37.  
  38.             src = src->next;
  39.             dst = dst->next;
  40.         }
  41.  
  42.         src->next = new Node(dst->value);
  43.  
  44.     }
  45.  
  46. public:
  47.     struct Node
  48.     {
  49.         Node* next;
  50.         INT value;
  51.  
  52.         Node(INT val = 0, Node* next = NULL) : value(val), next(next) {}
  53.  
  54.         ~Node()
  55.         {
  56.             if (next)
  57.                 delete next;
  58.         }
  59.  
  60.     } *Head;
  61. };
  62.  
  63. int main()
  64. {
  65.  
  66.     List a, b;
  67.  
  68.     a.add(10);
  69.     a.add(50);
  70.     a.add(780);
  71.     a.add(13);
  72.  
  73.  
  74.     for (List::Node* p = a.Head; p->next; p = p->next)
  75.     {
  76.         cout << p->value << endl;
  77.     }
  78.  
  79.     cout << endl;
  80.  
  81.     b.copy(a);
  82.  
  83.     for (List::Node* p = b.Head; p->next; p = p->next)
  84.     {
  85.         cout << p->value << endl;
  86.     }
  87.  
  88.     return 0;
  89. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
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