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) {
- while (*LinkN != 0) {
- cout << (*LinkN)->Text << endl;
- *LinkN = (*LinkN)->Next;
- }
- }
- void Clear(Link **LinkN) {;
- Link *Next;
- while (*LinkN != 0) {
- Next = (*LinkN)->Next;
- delete *LinkN;
- *LinkN = Next;
- }
- *LinkN = NULL;
- }
- void Add(Link **StartP) {
- uint8_t End = 0;
- char input[SizeArr];
- while (End == 0) {
- cin.getline(input, SizeArr);
- if (input[0] == '-') {
- End = 1;
- }
- else {
- if (*StartP == 0) {
- *StartP = new Link;
- strcpy_s((*StartP)->Text, input);
- (*StartP)->Next = 0;
- }
- else {
- Link *Prev = *StartP;
- Link *WorkStart = *StartP;
- while (WorkStart != 0) {
- Prev = WorkStart;
- WorkStart = WorkStart->Next;
- }
- WorkStart = Prev;
- Link *NewStart = new Link;
- WorkStart->Next = NewStart;
- WorkStart = WorkStart->Next;
- strcpy_s(NewStart->Text, input);
- NewStart->Next = 0;
- }
- }
- }
- }
- int main()
- {
- cout << "Inser text line by line, end with inserting -"<< endl << endl;
- Link *First = NULL;
- Add(&First);
- PrintThemAll(&First);
- Clear(&First);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement