codisinmyvines

Dlya Dineslama

Oct 7th, 2020 (edited)
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include "list.h"
  2. #include <iostream>
  3. #include <fstream>
  4. List::List()
  5. {
  6.     top = 0;
  7.     this->Reset();
  8. }
  9. void List::Reset()
  10. {
  11.     marker = top;
  12.     pred = top;
  13. }
  14. void List::Move()
  15. {
  16.     if (!this->EoList())
  17.     {
  18.         if (marker == pred)
  19.             marker = marker->next;
  20.         else
  21.         {
  22.             marker = marker->next;
  23.             pred = pred->next;
  24.         }
  25.     }
  26. }
  27. bool List::EoList()
  28. {
  29.     return marker == 0;
  30. }
  31. void List::Add(int a)
  32. {
  33.     node* q;
  34.     if (top == marker)
  35.     {
  36.         q = new node;
  37.         q->data = a;
  38.         q->next = marker;
  39.         top = q;
  40.         pred = q;
  41.     }
  42.     else
  43.     {
  44.         q = new node;
  45.         q->data = a;
  46.         pred->next = q;
  47.         q->next = marker;
  48.         pred = pred->next;
  49.     }
  50. }
  51. void List::Del()
  52. {
  53.     node* q;
  54.     if (marker != 0)
  55.     {
  56.         if (top == marker)
  57.         {
  58.             top = top->next;
  59.             marker = top->next;
  60.             q = pred;
  61.             delete q;
  62.             pred = top;
  63.         }
  64.         else
  65.         {
  66.             marker = marker->next;
  67.             q = pred->next;
  68.             pred->next = marker;
  69.             delete q;
  70.         }
  71.     }
  72. }
  73. void List::Show()
  74. {
  75.     node* q = top;
  76.     while (q != 0)
  77.     {
  78.         std::cout << q->data << " ";
  79.         q = q->next;
  80.     }
  81. }
Add Comment
Please, Sign In to add comment