Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. //main
  2.  
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <sstream>
  7.  
  8. #include "functions.h"
  9. #include "structures.h"
  10.  
  11.  
  12. int main() {
  13. std::ofstream zapis("o.txt");
  14. std::ifstream odczyt_i("i.txt");
  15. std::ifstream odczyt_t("t.txt");
  16.  
  17. element_double * pHead_list3 = nullptr;
  18. listOflists * pHead_list1 = nullptr, *pHead_list2 = nullptr;
  19. branch * pRoot = nullptr;
  20.  
  21. int idx = 0;
  22. typ line;
  23. if (getline(odczyt_t, line)) {
  24. branch* root = tworz_korzen(line);
  25. while (getline(odczyt_t, line)) {
  26. auto rodzic = znajdz_o_indeksie(root, idx);
  27. }
  28. }
  29. //czlowiek ludz;
  30. //if (getline(odczyt_i, line)) {
  31. // typ etykieta = CheckTree(pRoot, ludz);
  32. //}
  33. branch* Root;
  34.  
  35. znajdz_o_indeksie(Root, 0);
  36.  
  37. czlowiek *pHead = nullptr;
  38. double val = znajdz_w_tablicy(pHead, ktos);
  39. if (val oper value) {
  40.  
  41. }
  42. typ label;
  43. return label;
  44.  
  45.  
  46. //if (odczyt_t) {
  47. // branch b;
  48. // while (!odczyt_t.eof()) { //co zrobić z komentarzem?
  49. // odczyt_t >> b.indeks;
  50. // odczyt_t >> b.label;
  51. // odczyt_t >> b.oper;
  52. // odczyt_t >> b.val;
  53. // //TreeAdd(b, pRoot);
  54. // }
  55. // odczyt_t.close();
  56. //}
  57. typ etiq;
  58. double val=0.0;
  59. if (odczyt_i) {
  60. while (!odczyt_i.eof()) {
  61. List1Add(pHead_list1, etiq);
  62. }
  63. List2Add(pHead_list2, etiq, val);
  64.  
  65. //if(TreeCheck(val)){ //napisać funkcję do sprawdzania
  66. odczyt_i.close();
  67. }
  68. return 0;
  69. }
  70.  
  71. //struktury
  72.  
  73.  
  74. #ifndef structures_h
  75. #define structures_h
  76.  
  77. #include <iostream>
  78. #include <string>
  79. #include <sstream>
  80.  
  81. typedef std::string typ;
  82.  
  83. struct czlowiek {
  84. typ label;
  85. double atri;
  86. czlowiek *next = nullptr;
  87. };
  88.  
  89. struct homes {
  90. typ label;
  91. double val;
  92. homes *next = nullptr;
  93. };
  94.  
  95. struct list
  96. {
  97. list *next = nullptr;
  98. double val;
  99. };
  100.  
  101. struct listOflists
  102. {
  103. typ label;
  104. listOflists * bNext = nullptr;
  105. list * sNext = nullptr;
  106. };
  107.  
  108. struct element_double
  109. {
  110. double atri;
  111. element_double * pNext;
  112. };
  113.  
  114. struct branch
  115. {
  116. int indeks;
  117. typ label;
  118. char oper;
  119. double val;
  120. branch *left, *right;
  121. };
  122.  
  123. #endif
  124.  
  125. //funkcje.h
  126.  
  127. #ifndef functions_h
  128. #define functions_h
  129.  
  130. #include <iostream>
  131. #include <string>
  132. #include <sstream>
  133.  
  134. #include "structures.h"
  135.  
  136. branch* tworz_korzen(const std::string& linia);
  137.  
  138. void List_end_Add(element_double * & pHead, double atri);
  139.  
  140. branch* znajdz_o_indeksie(branch* root, int index);
  141.  
  142. void List2Add(listOflists * pHead, typ label, double atri);
  143.  
  144. void List1Add(listOflists * & pHead, typ label);
  145.  
  146. typ CheckTree(branch* root, typ label);
  147.  
  148.  
  149. // if (file.good())
  150. // {
  151. // myList<int> m1;
  152. // string line;
  153. // while (getline(file, line))
  154. // {
  155. // istringstream strstrm(line);
  156. // int number;
  157. // m1.clean();
  158. // while (strstrm >> number)
  159. // {
  160. // m1.Add(number);
  161. // }
  162. // population.Add(m1);
  163. // }
  164.  
  165.  
  166. #endif
  167.  
  168. // funckje.cpp
  169.  
  170. #include <iostream>
  171. #include <string>
  172. #include <sstream>
  173.  
  174. #include "functions.h"
  175.  
  176. void List1Add(listOflists * & pHead, typ label) {
  177. if (!pHead)
  178. pHead = new listOflists{ label ,nullptr, nullptr };
  179. else
  180. List1Add(pHead->bNext, label);
  181. }
  182. void List2Add(listOflists * pHead, typ label, double atri) {
  183. if (!(pHead->label == label))
  184. List2Add(pHead->bNext, label, atri);
  185. else {
  186. list* dod = new list;
  187. dod->val = atri;
  188. auto p = pHead->sNext;
  189. while (p->next) {
  190. p = p->next;
  191. }
  192. p->next = dod;
  193. }
  194. }
  195.  
  196.  
  197. branch* znajdz_o_indeksie(branch* root, int index) {
  198. if (!root)
  199. return nullptr;
  200. branch* l = znajdz_o_indeksie(root->left, index);
  201. if (l)
  202. return l;
  203. return znajdz_o_indeksie(root->right, index);
  204. }
  205.  
  206. branch* tworz_korzen(const std::string& linia) {
  207. int nr;
  208. std::istringstream str(linia);
  209. str >> nr;
  210. typ n;
  211. char op;
  212. double wart;
  213. str >> n >> op >> wart;
  214. branch* korzen = new branch{ nr, n, op, wart, nullptr, nullptr };
  215. //if(warunek.find(
  216. if (str >> nr) {
  217. korzen->left = new branch{ nr, "", ' ', 0.0, nullptr, nullptr };
  218. }
  219. else {
  220. typ nazwa;
  221. str.clear();
  222. str >> nazwa;
  223. korzen->left = new branch{ nr, nazwa, ' ', 0.0, nullptr, nullptr };
  224. }
  225. if (str >> nr) {
  226. korzen->right = new branch{ nr, "", ' ', 0.0, nullptr, nullptr };
  227. }
  228. else {
  229. std::string nazwa;
  230. str.clear();
  231. str >> nazwa;
  232. korzen->right = new branch{ nr, nazwa, ' ', 0.0, nullptr, nullptr };
  233. }
  234. return korzen;
  235. }
  236.  
  237. double znajdz_w_tablicy(czlowiek*pHead, czlowiek ktos) {
  238. if (!(pHead->label == ktos.label))
  239. return znajdz_w_tablicy(pHead->next, ktos);
  240. else
  241. return ktos.atri;
  242. }
  243.  
  244. //typ CheckTree(branch* root, czlowiek ktos) {
  245. // znajdz_o_indeksie(root, 0)
  246. // czlowiek *pHead = nullptr;
  247. // double val = znajdz_w_tablicy(pHead, ktos);
  248. // if (val oper value) {
  249. //
  250. // }
  251. // typ label;
  252. // return label;
  253. //}
  254.  
  255. void List_end_Add(element_double * & pHead, double atri) {
  256. if (!pHead)
  257. pHead = new element_double{ atri, nullptr };
  258. else
  259. List_end_Add(pHead->pNext, atri);
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement