Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //main
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include "functions.h"
- #include "structures.h"
- int main() {
- std::ofstream zapis("o.txt");
- std::ifstream odczyt_i("i.txt");
- std::ifstream odczyt_t("t.txt");
- element_double * pHead_list3 = nullptr;
- listOflists * pHead_list1 = nullptr, *pHead_list2 = nullptr;
- branch * pRoot = nullptr;
- int idx = 0;
- typ line;
- if (getline(odczyt_t, line)) {
- branch* root = tworz_korzen(line);
- while (getline(odczyt_t, line)) {
- auto rodzic = znajdz_o_indeksie(root, idx);
- }
- }
- //czlowiek ludz;
- //if (getline(odczyt_i, line)) {
- // typ etykieta = CheckTree(pRoot, ludz);
- //}
- branch* Root;
- znajdz_o_indeksie(Root, 0);
- czlowiek *pHead = nullptr;
- double val = znajdz_w_tablicy(pHead, ktos);
- if (val oper value) {
- }
- typ label;
- return label;
- //if (odczyt_t) {
- // branch b;
- // while (!odczyt_t.eof()) { //co zrobić z komentarzem?
- // odczyt_t >> b.indeks;
- // odczyt_t >> b.label;
- // odczyt_t >> b.oper;
- // odczyt_t >> b.val;
- // //TreeAdd(b, pRoot);
- // }
- // odczyt_t.close();
- //}
- typ etiq;
- double val=0.0;
- if (odczyt_i) {
- while (!odczyt_i.eof()) {
- List1Add(pHead_list1, etiq);
- }
- List2Add(pHead_list2, etiq, val);
- //if(TreeCheck(val)){ //napisać funkcję do sprawdzania
- odczyt_i.close();
- }
- return 0;
- }
- //struktury
- #ifndef structures_h
- #define structures_h
- #include <iostream>
- #include <string>
- #include <sstream>
- typedef std::string typ;
- struct czlowiek {
- typ label;
- double atri;
- czlowiek *next = nullptr;
- };
- struct homes {
- typ label;
- double val;
- homes *next = nullptr;
- };
- struct list
- {
- list *next = nullptr;
- double val;
- };
- struct listOflists
- {
- typ label;
- listOflists * bNext = nullptr;
- list * sNext = nullptr;
- };
- struct element_double
- {
- double atri;
- element_double * pNext;
- };
- struct branch
- {
- int indeks;
- typ label;
- char oper;
- double val;
- branch *left, *right;
- };
- #endif
- //funkcje.h
- #ifndef functions_h
- #define functions_h
- #include <iostream>
- #include <string>
- #include <sstream>
- #include "structures.h"
- branch* tworz_korzen(const std::string& linia);
- void List_end_Add(element_double * & pHead, double atri);
- branch* znajdz_o_indeksie(branch* root, int index);
- void List2Add(listOflists * pHead, typ label, double atri);
- void List1Add(listOflists * & pHead, typ label);
- typ CheckTree(branch* root, typ label);
- // if (file.good())
- // {
- // myList<int> m1;
- // string line;
- // while (getline(file, line))
- // {
- // istringstream strstrm(line);
- // int number;
- // m1.clean();
- // while (strstrm >> number)
- // {
- // m1.Add(number);
- // }
- // population.Add(m1);
- // }
- #endif
- // funckje.cpp
- #include <iostream>
- #include <string>
- #include <sstream>
- #include "functions.h"
- void List1Add(listOflists * & pHead, typ label) {
- if (!pHead)
- pHead = new listOflists{ label ,nullptr, nullptr };
- else
- List1Add(pHead->bNext, label);
- }
- void List2Add(listOflists * pHead, typ label, double atri) {
- if (!(pHead->label == label))
- List2Add(pHead->bNext, label, atri);
- else {
- list* dod = new list;
- dod->val = atri;
- auto p = pHead->sNext;
- while (p->next) {
- p = p->next;
- }
- p->next = dod;
- }
- }
- branch* znajdz_o_indeksie(branch* root, int index) {
- if (!root)
- return nullptr;
- branch* l = znajdz_o_indeksie(root->left, index);
- if (l)
- return l;
- return znajdz_o_indeksie(root->right, index);
- }
- branch* tworz_korzen(const std::string& linia) {
- int nr;
- std::istringstream str(linia);
- str >> nr;
- typ n;
- char op;
- double wart;
- str >> n >> op >> wart;
- branch* korzen = new branch{ nr, n, op, wart, nullptr, nullptr };
- //if(warunek.find(
- if (str >> nr) {
- korzen->left = new branch{ nr, "", ' ', 0.0, nullptr, nullptr };
- }
- else {
- typ nazwa;
- str.clear();
- str >> nazwa;
- korzen->left = new branch{ nr, nazwa, ' ', 0.0, nullptr, nullptr };
- }
- if (str >> nr) {
- korzen->right = new branch{ nr, "", ' ', 0.0, nullptr, nullptr };
- }
- else {
- std::string nazwa;
- str.clear();
- str >> nazwa;
- korzen->right = new branch{ nr, nazwa, ' ', 0.0, nullptr, nullptr };
- }
- return korzen;
- }
- double znajdz_w_tablicy(czlowiek*pHead, czlowiek ktos) {
- if (!(pHead->label == ktos.label))
- return znajdz_w_tablicy(pHead->next, ktos);
- else
- return ktos.atri;
- }
- //typ CheckTree(branch* root, czlowiek ktos) {
- // znajdz_o_indeksie(root, 0)
- // czlowiek *pHead = nullptr;
- // double val = znajdz_w_tablicy(pHead, ktos);
- // if (val oper value) {
- //
- // }
- // typ label;
- // return label;
- //}
- void List_end_Add(element_double * & pHead, double atri) {
- if (!pHead)
- pHead = new element_double{ atri, nullptr };
- else
- List_end_Add(pHead->pNext, atri);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement