Advertisement
nicx321

LL_StringSave

Dec 23rd, 2018
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.12 KB | None | 0 0
  1. // ConsoleApplication1.cpp : Tento soubor obsahuje funkci main. Provádění programu se tam zahajuje a ukončuje.
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. #define SizeArr 40
  10.  
  11. class Link {
  12. public:
  13.     char Text[SizeArr];
  14.     Link *Next;
  15.     Link() {
  16.         for (int i = 0; i < SizeArr; i++) {
  17.             Text[i] = 0;
  18.         }
  19.     }
  20. };
  21.  
  22. void PrintThemAll(Link **LinkN) {
  23.     Link *Curr = *LinkN;
  24.     while (Curr != NULL) {
  25.         cout << Curr->Text << endl;
  26.         Curr = Curr->Next;
  27.     }
  28. }
  29.  
  30. void PrintThemAll_A(Link **LinkN) {
  31.     Link *Curr = *LinkN;
  32.     while (Curr != NULL) {
  33.         cout << Curr << ": " << Curr->Text << endl;
  34.         Curr = Curr->Next;
  35.     }
  36. }
  37.  
  38. void PoP(Link **LinkN) {
  39.     Link *Next = *LinkN;
  40.     Link *Prev = Next;
  41.     Link *PrevPrev = Prev;
  42.     int i = 0;
  43.     while (Next != NULL) {
  44.         PrevPrev = Prev;
  45.         Prev = Next;
  46.         Next = Next->Next;
  47.         i++;
  48.     }
  49.     if (i == 0) {
  50.  
  51.     }
  52.     else if (i == 1) {
  53.         delete *LinkN;
  54.         *LinkN = NULL;
  55.     }
  56.     else {
  57.         delete Prev;
  58.         PrevPrev->Next = NULL;
  59.     }
  60. }
  61.  
  62. void Clear(Link **LinkN) {;
  63.     Link *Next;
  64.     while (*LinkN != NULL) {
  65.         Next = (*LinkN)->Next;
  66.         delete *LinkN;
  67.         *LinkN = Next;
  68.     }
  69. }
  70.  
  71. void Addlink(Link **StartP, char Text[SizeArr]) {
  72.     if (*StartP == NULL) {
  73.         *StartP = new Link;
  74.         strcpy_s((*StartP)->Text, Text);
  75.         (*StartP)->Next = 0;
  76.     }
  77.     else {
  78.         Link *Prev = *StartP;
  79.         Link *WorkStart = *StartP;
  80.         while(WorkStart != NULL) {
  81.             Prev = WorkStart;
  82.             WorkStart = WorkStart->Next;
  83.         }
  84.         WorkStart = Prev;
  85.         Link *NewStart = new Link;
  86.         WorkStart->Next = NewStart;
  87.         WorkStart = WorkStart->Next;
  88.         strcpy_s(NewStart->Text, Text);
  89.         NewStart->Next = NULL;
  90.     }
  91. }
  92.  
  93. void FillText(Link **StartP) {
  94.     uint8_t End = 0;
  95.     char input[SizeArr];
  96.     while (End == 0) {
  97.         cin.getline(input, SizeArr);
  98.         if (input[0] == '-') {
  99.             End = 1;
  100.         }
  101.         else {
  102.             Addlink(StartP, input);
  103.         }
  104.     }
  105. }
  106.  
  107. int main()
  108. {
  109.     cout << "Inser text line by line, end with inserting -" << endl << endl;
  110.     Link *LinkedList = NULL;
  111.     FillText(&LinkedList);
  112.     PrintThemAll_A(&LinkedList);
  113.     PoP(&LinkedList);
  114.     cout << endl;
  115.     PrintThemAll_A(&LinkedList);
  116.     Clear(&LinkedList);
  117.     delete LinkedList;
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement