Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- using namespace std;
- ifstream in("input.txt");
- ofstream out("output.txt");
- class list
- {
- struct element
- {
- string inf;
- element* next;
- element(string x) :inf(x), next(0) {}
- };
- int count = 0;
- element* head;
- int size;
- element* findx(string x)
- {
- element* cur = head;
- for (int i = 1; i < size; i++)
- {
- if (cur->inf == x)
- {
- return cur;
- }
- cur = cur->next;
- }
- }
- element* find(int index)
- {
- if ((index < 0) || (index > size))
- {
- return nullptr;
- }
- else
- {
- element* cur = head;
- for (int i = 1; i < index; i++)
- {
- cur = cur->next;
- }
- return cur;
- }
- }
- public:
- list() :head(0), size(0) {}
- bool empty()
- {
- return head == 0;
- }
- int getlength()
- {
- return size;
- }
- string getx(string x)
- {
- element* r = findx(x);
- string i = r->inf;
- return i;
- }
- string get(int index)
- {
- element* r = find(index);
- string i = r->inf;
- return i;
- }
- void insert(int index, string data)
- {
- element* newptr = new element(data);
- size = getlength() + 1;
- if (index == 1)
- {
- newptr->next = head;
- head = newptr;
- }
- else
- {
- element* prev = find(index - 1);
- newptr->next = prev->next;
- prev->next = newptr;
- }
- }
- void remove(int index)
- {
- element* cur;
- --size;
- if (index == 1)
- {
- cur = head;
- head = head->next;
- }
- else
- {
- element* prev = find(index - 1);
- cur = prev->next;
- prev->next = cur->next;
- }
- cur->next = nullptr;
- delete cur;
- }
- void print()
- {
- for (element* cur = head; cur != nullptr; cur = cur->next)
- {
- out << cur->inf << ' ';
- }
- out << endl;
- }
- };
- int main()
- {
- list ls, kk;
- string value;
- while (in >> value)
- {
- ls.insert(ls.getlength() + 1, value);
- }
- in.close();
- int ind = 1;
- while (!ls.empty()) {
- string i = ls.get(0);
- kk.insert(ind, i);
- ind++;
- if (i.length() == 1) {
- kk.insert(ind, i);
- ind++;
- }
- ls.remove(1);
- }
- kk.print();
- return 0;
- }
- aarrarar
- r
- t
- base
- baza
- h
- pp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement