Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. // SDiZO.cpp : Defines the entry point for the console application.
  2. //
  3. #include <iostream>
  4.  
  5. #include "stdafx.h"
  6. #include "Tablica.h"
  7. #include "ListaDwukierunkowa.h"
  8. #include "Heap.h"
  9.  
  10. #include <stdio.h>
  11. #include <cstdlib>
  12. #include <conio.h>
  13. using namespace std;
  14.  
  15. void usun(Tablica t1)
  16. {
  17. char skad;
  18. cout << "Skąd usunąć wartość?" << endl;
  19. cout << "1. Z końca" << endl;
  20. cout << "2. Z poczatku" << endl;
  21. cout << "3. Ze srodka" << endl;
  22. cin >> skad;
  23. switch (skad)
  24. {
  25. case'1':
  26. t1.pop_front();
  27. t1.show();
  28. break;
  29. case '2':
  30. t1.pop_back();
  31. t1.show();
  32. break;
  33. case '3':
  34. int n;
  35. cout << "Podaj liczbe" << endl;
  36. cin >> n;
  37. t1.pop_middle(n);
  38. t1.show();
  39. break;
  40. }
  41.  
  42. }
  43.  
  44.  
  45. void addTab(Tablica t1)
  46. {
  47. char dokad;
  48. cout << "Gdzie dodac wartosc?" << endl;
  49. cout << "1. Na koniec" << endl;
  50. cout << "2. Na poczatek" << endl;
  51. cout << "3. Na srodek" << endl;
  52. cin >> dokad;
  53. switch (dokad)
  54. {
  55. case'1':
  56. int n;
  57. cout << "Podaj liczbe";
  58. cin >> n;
  59. t1.push_back(n);
  60. t1.show();
  61. break;
  62. case '2':
  63. int o;
  64. cout << "Podaj liczbe";
  65. cin >> o;
  66. t1.push_front(o);
  67. t1.show();
  68. break;
  69. case '3':
  70. int p, r;
  71. cout << "Podaj pozycje wstawienia";
  72. cin >> p;
  73. cout << "Podaj liczbe";
  74. cin >> r;
  75. t1.push_rand(p, r);
  76. t1.show();
  77. break;
  78. }
  79. }
  80. void usunList(ListaDwukierunkowa lista)
  81. {
  82. char usun;
  83. cout << "Skad usunac? ";
  84. cout << "1. z początku";
  85. cout << "2. z końca";
  86. cin >> usun;
  87. switch (usun)
  88. {
  89. case '1': lista.del_head();
  90. lista.display_head();
  91. break;
  92. case '2': lista.del_tail();
  93. lista.display_head();
  94. break;
  95. case '3':
  96. int index;
  97. cout << "Z ktorego miejsca usunac?"<<endl;
  98. cin >> index;
  99. lista.del_middle(index);
  100. lista.display_head();
  101. break;
  102. }
  103. }
  104. void dodajList(ListaDwukierunkowa lista)
  105. {
  106. char dodajList;
  107. int wartosc;
  108. cout << "Gdzie dodac?" << endl;
  109. cout << "1. Początek listy" << endl;
  110. cout << "2. Koniec listy" << endl;
  111. cout << "3. Srodek listy" << endl;
  112. cin >> dodajList;
  113. cout << "Podaj wartosc do dodania";
  114. cin >> wartosc;
  115. switch (dodajList)
  116. {
  117. case'1':
  118. lista.push_front(wartosc);
  119. lista.display_head();
  120. break;
  121. case '2':
  122.  
  123. lista.push_back(wartosc);
  124. lista.display_head();
  125. break;
  126. case '3':
  127.  
  128. int index;
  129. cout << "Gdzie wstawic?";
  130. cin >> index;
  131. lista.push_middle(wartosc, index);
  132. lista.display_head();
  133. break;
  134. }
  135.  
  136. }
  137. void wyswList(ListaDwukierunkowa lista)
  138. {
  139. int wysList, w;
  140. cout << "Wyswietlanie:" << endl;
  141. cout << "1. Głowa" << endl;
  142. cout << "2.Ogon" << endl;
  143. cin >> wysList;
  144. switch (wysList)
  145. {
  146. case'1':
  147.  
  148. lista.display_head();
  149. break;
  150. case '2':
  151. lista.display_tail();
  152. break;
  153. }
  154.  
  155. }
  156. int _tmain(int argc, _TCHAR* argv[])
  157. {
  158. Tablica t1;
  159. t1.push_front(5);
  160. t1.push_front(10);
  161. t1.push_front(11);
  162. t1.push_front(3);
  163. ListaDwukierunkowa lista;
  164. lista.push_front(12);
  165. lista.push_front(2);
  166. lista.push_front(1);
  167. lista.push_front(92);
  168. lista.push_front(15);
  169. lista.push_back(9999);
  170. lista.display_head();
  171. char wyb;
  172. cout << "Wybierz strukture:" << endl;
  173. cout << "1. Tablica." << endl;
  174. cout << "2.Lista" << endl;
  175. cout << "3.Kopiec." << endl;
  176. cout << "---------------------------------------------------------" << endl;
  177. cin >> wyb;
  178. // system("cls");
  179. while (true)
  180. {
  181. switch (wyb)
  182. {
  183. case '1':
  184. while (wyb != 'k')
  185. {
  186. char wybTab;
  187. cout << "Wybierz operacje na tablicy: " << endl;
  188. cout << "1. Zbuduj z pliku." << endl;
  189. cout << "2. Usun" << endl;
  190. cout << "3. Dodaj" << endl;
  191. cout << "4. Znajdz" << endl;
  192. cout << "5. Utworz losowo" << endl;
  193. cout << "6. Wyswietl" << endl;
  194. cin >> wybTab;
  195. switch (wybTab)
  196. {
  197. case'1':
  198. t1.from_file();
  199. t1.show();
  200. break;
  201. case '2':
  202. usun(t1);
  203. break;
  204. case '3':
  205. addTab(t1);
  206. break;
  207. case '4':
  208. int i;
  209. cout << "Jaka liczbe znalezc?";
  210. cin >> i;
  211. t1.search(i);
  212. t1.show();
  213. break;
  214. case '5':
  215. //losowe wyszukanie
  216. break;
  217. case '6':
  218. t1.show();
  219. break;
  220. case 'k':
  221. break;
  222. default:
  223. cout << "Nie ma takiej opcji" << endl;
  224. break;
  225. }
  226. }
  227. break;
  228. case '2':
  229. while (wyb != 'k')
  230. {
  231. char wybList;
  232. cout << "Wybierz operacje na liście: " << endl;
  233. cout << "1. Zbuduj z pliku." << endl;
  234. cout << "2. Usun" << endl;
  235. cout << "3. Dodaj" << endl;
  236. cout << "4. Znajdz" << endl;
  237. cout << "5. Utworz losowo" << endl;
  238. cout << "6. Wyswietl" << endl;
  239. cin >> wybList;
  240. switch (wybList)
  241. {
  242. case '1':
  243. //zbuduj z pliku
  244. break;
  245. case'2':
  246. usunList(lista);
  247. break;
  248. case'3':
  249. dodajList(lista);
  250. break;
  251. case'4':
  252. // znajdz
  253. break;
  254. case'5':
  255. //losowo
  256. break;
  257. case'6':
  258. wyswList(lista);
  259. break;
  260. case 'k':
  261. break;
  262. default:
  263. cout << "Nie ma takiej opcji" << endl;
  264. break;
  265. }
  266.  
  267.  
  268. }
  269. }
  270.  
  271.  
  272. }
  273.  
  274. cin.get();
  275. system("Pause");
  276.  
  277.  
  278.  
  279. return 0;
  280.  
  281.  
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement