G2A Many GEOs
SHARE
TWEET

Untitled

a guest Apr 4th, 2020 198 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include<math.h>
  3. using namespace std;
  4. class List {
  5. public:
  6.     int number;
  7. };
  8.  
  9. class OBJ {
  10. public:
  11.     List b;
  12.     class OBJ* prev, * next;
  13. };
  14. OBJ* head = NULL; OBJ* tail = NULL;
  15. void add_obj(OBJ* obj, List list) {
  16.     OBJ* ptr = new OBJ;
  17.     ptr->b = list;
  18.     ptr->prev = obj;
  19.     ptr->next = (obj == NULL) ? NULL : obj->next;
  20.     if (obj != NULL) {
  21.         obj->next = ptr;
  22.         if (obj->next != NULL) obj->next->prev = ptr;
  23.     }
  24.     if (ptr->prev == NULL) head = ptr;
  25.     if (ptr->next == NULL) tail = ptr;
  26. }
  27. void show() {
  28.     OBJ* c = head;
  29.     while (c != NULL) {
  30.         cout << c->b.number << endl;
  31.         c = c->next;
  32.     }
  33. }
  34. void reverse(OBJ*& head)
  35. {
  36.     OBJ* pred = NULL;
  37.     OBJ* current = head;
  38.     while (current != NULL)
  39.     {
  40.         OBJ* next2 = current->next;
  41.         current->next = pred;
  42.         pred = current;
  43.         current = next2;
  44.     }
  45.  
  46.     head = pred;
  47. }
  48.  
  49. int main() {
  50.     int N = 6;
  51.     setlocale(LC_ALL, "rus");
  52.     List a = { 0 };
  53.     add_obj(tail, a);
  54.     for (int i = 1; i < N; i++) {
  55.         a.number = i;
  56.         add_obj(tail, a);
  57.     }
  58.     show();
  59.     reverse(head);
  60.     show ();
  61.     return 0;
  62. }
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