Advertisement
Mikhail-Podbolotov

Untitled

May 8th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #include "library.h"
  2.  
  3. List::List()
  4. {
  5.     Start = End = nullptr;
  6. }
  7.  
  8. List::~List()
  9. {
  10.     Point* prom;
  11.     Point* t = Start;
  12.     while (t != 0) {
  13.         prom = t;
  14.         t = t->NextPoint;
  15.         delete prom;
  16.     }
  17. }
  18.  
  19. Point* List::getStart()
  20. {
  21.     return Start;
  22. }
  23.  
  24. int List::GetLast()
  25. {
  26.     return End->number;
  27. }
  28.  
  29. void List::addPoint()
  30. {
  31.     Point* temp = new Point;
  32.     if (Start == nullptr) {
  33.         temp->number = 1;
  34.         Start = End = temp;
  35.     }
  36.     else {
  37.         temp->number = End->number + 1;
  38.         End->NextPoint = temp;
  39.         End = temp;
  40.     }
  41. }
  42.  
  43. void List::addAdjPoint(int x)
  44. {
  45.     Point* tempPoint = End;
  46.     AdjPoint* tempAdjPoint = new AdjPoint;
  47.     tempAdjPoint->value = x;
  48.     if (tempPoint->First == nullptr)
  49.         tempPoint->First = tempPoint->Last = tempAdjPoint;
  50.     else {
  51.         tempPoint->Last->next = tempAdjPoint;
  52.         tempPoint->Last = tempAdjPoint;
  53.     }
  54. }
  55.  
  56. void List::Print(std::ofstream& file)
  57. {
  58.     Point* CurPoint = Start;
  59.     while (CurPoint != nullptr) {
  60.         file << CurPoint->number << ": ";
  61.         AdjPoint* CurAdjPoint = CurPoint->First;
  62.         while (CurAdjPoint != nullptr) {
  63.             file << CurAdjPoint->value << " ";
  64.             CurAdjPoint = CurAdjPoint->next;
  65.         }
  66.         file << endl;
  67.         CurPoint = CurPoint->NextPoint;
  68.     }
  69. }
  70.  
  71. void List::Read(std::ifstream& file)
  72. {
  73.     string line;
  74.     while (!file.eof()) {
  75.         getline(file, line);
  76.         addPoint();
  77.         int tempvalue = 0;
  78.         for (char c : line) {
  79.             if (isdigit(c)) {
  80.                 tempvalue += tempvalue * 10 + ((int)c - (int)'0');
  81.             }
  82.             else {
  83.                 if (tempvalue > 0) {
  84.                     addAdjPoint(tempvalue);
  85.                 }
  86.                 tempvalue = 0;
  87.             }
  88.         }
  89.         if (tempvalue > 0) {
  90.             addAdjPoint(tempvalue);
  91.         }
  92.     }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement