Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : Tento soubor obsahuje funkci main. Provádění programu se tam zahajuje a ukončuje.
- //
- #include "pch.h"
- #include <iostream>
- using namespace std;
- #define SizeArr 40
- class Link {
- public:
- char Text[SizeArr];
- Link *Next;
- Link() {
- for (int i = 0; i < SizeArr; i++) {
- Text[i] = 0;
- }
- }
- };
- void PrintThemAll(Link **LinkN) {
- Link *Curr = *LinkN;
- while (Curr != NULL) {
- cout << Curr->Text << endl;
- Curr = Curr->Next;
- }
- }
- void PrintThemAll_A(Link **LinkN) {
- Link *Curr = *LinkN;
- while (Curr != NULL) {
- cout << Curr << ": " << Curr->Text << endl;
- Curr = Curr->Next;
- }
- }
- void PoP(Link **LinkN) {
- Link *Next = *LinkN;
- Link *Prev = Next;
- Link *PrevPrev = Prev;
- int i = 0;
- while (Next != NULL) {
- PrevPrev = Prev;
- Prev = Next;
- Next = Next->Next;
- i++;
- }
- if (i == 0) {
- }
- else if (i == 1) {
- delete *LinkN;
- *LinkN = NULL;
- }
- else {
- delete Prev;
- PrevPrev->Next = NULL;
- }
- }
- void Clear(Link **LinkN) {;
- Link *Next;
- while (*LinkN != NULL) {
- Next = (*LinkN)->Next;
- delete *LinkN;
- *LinkN = Next;
- }
- }
- void Addlink(Link **StartP, char Text[SizeArr]) {
- if (*StartP == NULL) {
- *StartP = new Link;
- strcpy_s((*StartP)->Text, Text);
- (*StartP)->Next = 0;
- }
- else {
- Link *Prev = *StartP;
- Link *WorkStart = *StartP;
- while(WorkStart != NULL) {
- Prev = WorkStart;
- WorkStart = WorkStart->Next;
- }
- WorkStart = Prev;
- Link *NewStart = new Link;
- WorkStart->Next = NewStart;
- WorkStart = WorkStart->Next;
- strcpy_s(NewStart->Text, Text);
- NewStart->Next = NULL;
- }
- }
- void FillText(Link **StartP) {
- uint8_t End = 0;
- char input[SizeArr];
- while (End == 0) {
- cin.getline(input, SizeArr);
- if (input[0] == '-') {
- End = 1;
- }
- else {
- Addlink(StartP, input);
- }
- }
- }
- int main()
- {
- cout << "Inser text line by line, end with inserting -" << endl << endl;
- Link *LinkedList = NULL;
- FillText(&LinkedList);
- PrintThemAll_A(&LinkedList);
- PoP(&LinkedList);
- cout << endl;
- PrintThemAll_A(&LinkedList);
- Clear(&LinkedList);
- delete LinkedList;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement