Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <cstdlib>
- using namespace std;
- struct element
- {
- string data;
- element* next;
- element* prev;
- };
- struct dlist
- {
- element* head;
- element* tail;
- int liczba_elementow;
- };
- struct stos
- {
- string data;
- stos* next;
- };
- dlist create_empty_list();
- element* create_element(string n_d);
- void import_data(string patch, dlist &dl);
- void push(stos* &st, string new_data);
- void pop(stos* &st);
- string import(stos* st);
- void add_tail(string n_d, dlist &dl);
- void wyswietl_liste(dlist dl);
- int main()
- {
- dlist dl = create_empty_list();
- import_data("inversed.txt",dl);
- wyswietl_liste(dl);
- system("pause");
- return 0;
- }
- dlist create_empty_list()
- {
- dlist dl;
- dl.head = nullptr;
- dl.tail = nullptr;
- dl.liczba_elementow=0;
- return dl;
- }
- element* create_element(string n_d)
- {
- element* n_e = new element;
- n_e->data=n_d;
- n_e->next=nullptr;
- n_e->prev=nullptr;
- return n_e;
- }
- void import_data(string patch, dlist &dl)
- {
- stos* st = nullptr;
- ifstream file;
- string slowo, zdanie;
- file.open(patch);
- char temp;
- while(file>>slowo)
- {
- while(1)
- {
- if(slowo[slowo.size()-1] == '?' || slowo[slowo.size()-1] == '!' || slowo[slowo.size()-1] == '.')
- {
- temp = slowo[slowo.size()-1];
- slowo.pop_back();
- push(st, slowo);
- break;
- }
- push(st,slowo);
- file>>slowo;
- if(file.eof()) break;
- }
- ostringstream ss;
- while(st!=nullptr)
- {
- ss<<import(st)<<" ";
- pop(st);
- }
- zdanie=ss.str();
- zdanie.pop_back();
- zdanie.push_back(temp);
- ss.str("");
- add_tail(zdanie,dl);
- }
- file.close();
- }
- void push(stos* &st, string new_data)
- {
- stos* dodawany_element=new stos;
- dodawany_element->data=new_data;
- dodawany_element->next=st;
- st=dodawany_element;
- }
- void pop(stos* &st)
- {
- stos* temp = st;
- st=st->next;
- delete temp;
- }
- string import(stos* st)
- {
- string data_to_return=st->data;
- return data_to_return;
- }
- void add_tail(string n_d, dlist &dl)
- {
- element* n_e = create_element(n_d);
- if(dl.liczba_elementow==0)
- dl.head=n_e;
- else
- dl.tail->next=n_e;
- n_e->prev=dl.tail;
- dl.tail=n_e;
- dl.liczba_elementow++;
- }
- void wyswietl_liste(dlist dl)
- {
- element* temp=dl.head;
- do{
- cout<<temp->data<<endl;
- temp=temp->next;
- }while(temp!=nullptr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement