Advertisement
plokarzbartlomiej

main

Mar 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.83 KB | None | 0 0
  1. // SDiZO.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <cstdlib>
  6. #include <iostream>
  7. #include <fstream>
  8. #include <string>
  9. #include <ctime>
  10. #include "Array.cpp"
  11. #include "List.cpp"
  12. #include "BinaryHeap.cpp"
  13. #include <windows.h>
  14.  
  15. using namespace std;
  16.  
  17. int _tmain(int argc, _TCHAR* argv[])
  18. {
  19. Timerek *timerek= new Timerek();
  20. srand(time(NULL));
  21. bool toTheBeginning = true;
  22. while (toTheBeginning == true){
  23.  
  24. int choice;
  25. cout << "Choose structure to test" << endl
  26. << "1. Array" << endl << "2. List" << endl << "3. Heap" << endl << "4. Drzewo czerwono-czarne" << endl;
  27. cin >> choice;
  28.  
  29. system("cls");
  30. switch (choice)
  31. {
  32. case 1:
  33. {
  34. toTheBeginning = false;
  35. Array* array;
  36. array = new Array();
  37. int amount;
  38. while (toTheBeginning == false)
  39. {
  40. cout << "Array - " << array->amoutOfElements << " elementow" << endl << "What do you want to do?" <<
  41. endl << "1. Load from file " << endl << "2. Draw array" << endl << "3. Delete" << endl << "4. Add" << endl << "5. Search" <<
  42. endl << "6. Display" << endl << "7. Destroy" << endl << "8. Come back to the structure selection" << endl << "9. End program" << endl;
  43. cin >> choice;
  44.  
  45. switch (choice)
  46. {
  47. case 1:{
  48. string path;
  49. array = new Array();
  50. cout << "Enter file name" << endl;
  51. cin >> path;
  52. cout << endl;
  53. array->loadFromFile(path);
  54. } break;
  55. case 2:
  56. {
  57.  
  58. while (true)
  59. {
  60. cout << "How much elements should an array contain?" << endl;
  61. cin >> amount;
  62. if (amount <= 0) cout << "Enter number bigger than 0!" << endl;
  63. else break;
  64. }
  65. array = new Array();
  66. cout << endl;
  67. array->fillUpRandomly(amount);
  68. }break;
  69. case 3:{
  70. int value;
  71. cout << "1. Delete from the beginning " << endl << "2. Delete from the end" << endl << "3. Delete selected element" << endl;
  72. cin >> choice;
  73. switch (choice)
  74.  
  75. {
  76.  
  77. case 1:
  78. {
  79. array->deleteBeg();
  80.  
  81. }break;
  82.  
  83. case 2:
  84. {
  85. array->deleteEnd();
  86. }break;
  87. case 3:{
  88. while (true)
  89. {
  90. cout << "Enter the index of element" << endl;
  91. cin >> amount;
  92. cout << endl;
  93. if (amount < 0) cout << "Enter number bigger than 0!" << endl;
  94. else break;
  95. }
  96.  
  97. array->deleteByIndex(amount);
  98.  
  99. }break;
  100.  
  101. }
  102.  
  103. }break;
  104. case 4:{
  105. int value;
  106. cout << "1. Add at the beginning " << endl << "2. Add at the end" << endl << "3. Add at selected index" << endl;
  107. cin >> choice;
  108. switch (choice)
  109.  
  110. {
  111.  
  112. case 1:
  113. {
  114. cout << "Enter value of new element" << endl;
  115. cin >> value;
  116. cout << endl;
  117. timerek->counter = 0;
  118. timerek->startCounter();
  119. array->addBeg(value);
  120. timerek->getTime();
  121.  
  122. }break;
  123.  
  124. case 2:
  125. {
  126. cout << "Enter value of new element" << endl;
  127. cin >> value;
  128. cout << endl;
  129. array->addEnd(value);
  130. }break;
  131. case 3:{
  132. while (true)
  133. {
  134. cout << "Enter the index of new element" << endl;
  135. cin >> amount;
  136. cout << endl;
  137. if (amount < 0) cout << "Enter number bigger than 0!" << endl;
  138. else break;
  139. }
  140.  
  141. cout << "Enter value of the lement" << endl;
  142. cin >> value;
  143. cout << endl;
  144. array->add(amount, value);
  145.  
  146. }break;
  147.  
  148. }
  149.  
  150.  
  151. }break;
  152. case 5:{
  153. int value;
  154. cout << "Enter the value you are looking for" << endl;
  155. cin >> value;
  156. cout << endl;
  157. array->search(value);
  158. }break;
  159. case 6:{
  160. array->display();
  161. }break;
  162. case 7:{
  163. array->~Array();
  164. array = new Array();
  165. }break;
  166. case 8:{
  167. delete array;
  168. system("cls");
  169. toTheBeginning = true;
  170. }break;
  171. case 9:{
  172. delete array;
  173. return 0;
  174. }
  175. }
  176. }
  177. }break;
  178. case 2:{
  179. toTheBeginning = false;
  180. unsigned amount;
  181. List* list;
  182. list = new List();
  183.  
  184. while (toTheBeginning == false){
  185. cout << "List of - " << list->amountOfElements << "elements " << endl << "What do you want to do?" <<
  186. endl << "1. Load from file " << endl << "2. Draw a list" << endl << "3. Delete" << endl << "4. Add" << endl << "5. Search" <<
  187. endl << "6. Display" << endl << "7. Destroy" << endl << "8. Come back to the structure selection" << endl << "9. End program" << endl;
  188. cin >> choice;
  189. switch (choice)
  190. {
  191. case 1:{
  192. list->~List();
  193. list = new List();
  194. string path;
  195. cout << "Enter name of the file" << endl;
  196. cin >> path;
  197. cout << endl;
  198. list->loadFromFile(path);
  199. }break;
  200. case 2:{
  201. list->~List();
  202. while (true)
  203. {
  204. cout << "How much elements should list contain?" << endl;
  205. cin >> amount;
  206. cout << endl;
  207. if (amount <= 0) cout << "Enter number bigger than 0" << endl;
  208. else break;
  209. }
  210. list = new List();
  211. list->fillUpRandomly(amount);
  212. }break;
  213. case 3:{
  214. int value;
  215. cout << "1. Remove from the beginning " << endl << "2. Remove from the end" << endl << "3. Remove specified element" << endl;
  216. cin >> choice;
  217. switch (choice)
  218.  
  219. {
  220.  
  221. case 1:
  222. {
  223. list->deleteBeg();
  224.  
  225. }break;
  226.  
  227. case 2:
  228. {
  229. list->deleteEnd();
  230. }break;
  231. case 3:{
  232.  
  233. cout << "Enter the key of element you want to remove?" << endl;
  234. cin >> amount;
  235. cout << endl;
  236. list->deleteByKey(amount);
  237.  
  238. }break;
  239.  
  240. }
  241.  
  242. }break;
  243.  
  244. case 4:{
  245. int value;
  246. cout << "1. Add to the beginning " << endl << "2. Add at the end" << endl << "3. Add behind specified element" << endl;
  247. cin >> choice;
  248. switch (choice)
  249.  
  250. {
  251. case 1:
  252. {
  253. cout << "Enter the key of the new element" << endl;
  254. cin >> value;
  255. cout << endl;
  256. timerek -> counter = 0;
  257. timerek-> startCounter();
  258. list -> addBeg(value);
  259. timerek -> getTime();
  260.  
  261. }break;
  262.  
  263. case 2:
  264. {
  265. cout << "Enter the key of new element" << endl;
  266. cin >> value;
  267. cout << endl;
  268. timerek -> counter = 0;
  269. timerek -> startCounter();
  270. list -> addEnd(value);
  271. timerek -> getTime();
  272. }break;
  273. case 3:{
  274. int key;
  275. cout << "Enter the key to add" << endl;
  276. cin >> key;
  277. cout << endl;
  278. cout << "Behind which element do you want to add(enter the key)" << endl;
  279. cin >> amount;
  280. cout << endl;
  281. list -> addBehindGivenKey(amount, key);
  282.  
  283. }break;
  284.  
  285. }
  286.  
  287.  
  288.  
  289. }break;
  290. case 5:{
  291. cout << "Enter the key that you are looking for" << endl;
  292. cin >> amount;
  293. cout << endl;
  294. timerek -> counter = 0;
  295. timerek -> startCounter();
  296. list -> search(amount);
  297. timerek-> getTime();
  298. if (list -> search(amount)) cout << "There is an element that you were looking for" << endl;
  299. if (!list -> search(amount)) cout << "There is no such element" << endl;
  300.  
  301.  
  302. }break;
  303. case 6:{
  304. list -> display();
  305. }break;
  306. case 7:{
  307. list -> ~List();
  308. list = new List();
  309.  
  310.  
  311. }break;
  312. case 8:{
  313. delete list;
  314. system("cls");
  315. toTheBeginning = true;
  316.  
  317. }break;
  318. case 9:{
  319. delete list;
  320. return 0;
  321. }
  322. }
  323.  
  324.  
  325. }break;
  326. }
  327. case 3:{
  328. toTheBeginning = false;
  329. int amount;
  330. system("cls");
  331. Heap *heap;
  332. heap = new Heap();
  333. while (toTheBeginning == false)
  334. {
  335. cout << "Heap - " << heap->amountOfElements << " elements" << endl << "What do you want to do?" <<
  336. endl << "1. Load from file" << endl << "2. Draw a heap" << endl << "3. Delete" << endl << "4. Add" << endl << "5. Search" <<
  337. endl << "6. Display" << endl << "7. Destroy structure" << endl << "8. Come back to the structure selection" << endl << "9. End program" << endl;
  338. cin >> choice;
  339.  
  340. switch (choice)
  341. {
  342. case 1:{
  343. string path;
  344. cout << "Enter file name" << endl;
  345. cin >> path;
  346. cout << endl;
  347. heap = new Heap();
  348. // heap->loadFromFile(path);
  349. }break;
  350.  
  351. case 2:
  352. {
  353. while (true)
  354. {
  355. cout << "How big structure you want to make?" << endl;
  356. cin >> amount;
  357. if (amount > 0) break;
  358. else cout << "Enter number bigger than 0!" << endl;
  359.  
  360. }
  361. heap = new Heap();
  362. heap->fillUpRandomly(amount);
  363. }break;
  364. case 3:{
  365. cout << "What to remove?" << endl;
  366. cin >> amount;
  367. cout << endl;
  368. heap->deleteNumber(amount);
  369.  
  370. }break;
  371.  
  372. case 4:{
  373. cout << "Enter key of the element to add" << endl;
  374. cin >> amount;
  375. cout << endl;
  376. heap->add(amount);
  377.  
  378.  
  379. }break;
  380.  
  381. case 5:{
  382. cout << "Enter value that you are looking for" << endl;
  383. cin >> amount;
  384. cout << endl;
  385. timerek -> counter = 0;
  386. timerek -> startCounter();
  387. heap -> search(amount);
  388. timerek -> getTime();
  389. if (heap->search(amount)) cout << "There is an element that you were looking for" << endl;
  390. if (!heap->search(amount)) cout << "There is no such element" << endl;
  391. }break;
  392. case 6:{
  393. heap->display(" ", " ", 1);
  394. }break;
  395. case 7:{
  396. heap->~Heap();
  397. heap = new Heap();
  398. }break;
  399. case 8:{
  400. system("cls");
  401. delete heap;
  402. toTheBeginning = true;
  403. }break;
  404. case 9:{
  405. delete heap;
  406. return 0;
  407. }
  408. }
  409. }
  410.  
  411. }break;
  412. }
  413. }
  414. system("pause");
  415. return 0;
  416. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement