Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*Tema 6. liste de numere întregi 3 (implementate dinamic)
  6. Se dau urmatoarele clase:
  7. - Nod (int info);
  8. - Nod_simplu (nod * next) :Nod
  9. - Nod_dublu (nod * ante) :Nod_simplu
  10. - Nod_prioritate (int prio) :Nod_dublu
  11. - Coada_prioritati (elemente de tip Nod_Prioritate);
  12. - Coada_simpla : Coada prioritati (elementele au prioritati egale).
  13. Clasele derivate trebuie sa contina cel puțin constructori parametrizati (prin
  14. care sa se evidentieze transmiterea parametrilor către constructorul din clasa
  15. de baza) si destructorI. Să se exemplifice Heapsort utilizand coada cu
  16. prioritati și Insertionsort utilizand coada simpla.*/
  17.  
  18.  
  19.  
  20.  
  21. class Nod{
  22. protected:
  23. int info;
  24.  
  25. public:
  26. Nod()
  27. {
  28. info = 0;
  29. }
  30. Nod(int f)
  31. {
  32. info = f;
  33. }
  34. ~Nod();
  35. };
  36.  
  37. class Nod_simplu:protected Nod{
  38. protected:
  39. Nod *next ;
  40. public:
  41. Nod_simplu()
  42. {
  43. info = 0;
  44. next = NULL;
  45. }
  46. Nod_simplu(int val)
  47. {
  48. info = val;
  49. next = NULL;
  50. }
  51. ~Nod_simplu();
  52.  
  53. friend istream& operator>>(istream &inod_simplu,Nod_simplu &x);
  54. friend ostream& operator<<(ostream &onod_simplu,Nod_simplu &x);
  55. };
  56.  
  57. istream& operator>>(istream & inod_simplu,Nod_simplu &x)
  58. {
  59. inod_simplu >> x.info;
  60.  
  61. return inod_simplu;
  62. }
  63.  
  64. ostream& operator<<(ostream &onod_simplu,Nod_simplu &x)
  65. {
  66. onod_simplu << x.info;
  67. return onod_simplu;
  68. }
  69.  
  70. class Nod_dublu:protected Nod_simplu{
  71. protected:
  72. Nod * ante;
  73. public:
  74. Nod_dublu()
  75. {
  76. info = 0;
  77. ante = NULL;
  78. next = NULL;
  79. }
  80. Nod_dublu(int val)
  81. {
  82. info = val;
  83. ante = NULL;
  84. next = NULL;
  85. }
  86. ~Nod_dublu();
  87.  
  88. friend istream& operator>>(istream &inod_dublu,Nod_dublu &x);
  89. friend ostream& operator<<(ostream &onod_dublu,Nod_dublu &x);
  90. };
  91.  
  92. istream& operator>>(istream & inod_dublu,Nod_dublu &x)
  93. {
  94. inod_dublu >> x.info;
  95.  
  96. return inod_dublu;
  97. }
  98.  
  99. ostream& operator<<(ostream &onod_dublu,Nod_dublu &x)
  100. {
  101. onod_dublu << x.info;
  102. return onod_dublu;
  103. }
  104.  
  105.  
  106.  
  107.  
  108. class Nod_prioritate: protected Nod_dublu{
  109. protected:
  110. int prio;
  111.  
  112. public:
  113. Nod_prioritate()
  114. {
  115. prio = 0;
  116. info = 0;
  117. ante = NULL;
  118. next = NULL;
  119. }
  120. Nod_prioritate(int prior,int infor)
  121. {
  122. prio = prior;
  123. info = infor;
  124. ante = NULL;
  125. next = NULL;
  126. }
  127. ~Nod_prioritate();
  128. friend istream& operator>>(istream &inod_prior,Nod_prioritate &x);
  129. friend ostream& operator<<(ostream &onod_prior,Nod_prioritate &x);
  130. };
  131.  
  132. istream& operator>>(istream & inod_prior,Nod_prioritate &x)
  133. {
  134. inod_prior >> x.info;
  135. inod_prior >> x.prio;
  136. return inod_prior;
  137. }
  138.  
  139. ostream& operator<<(ostream &onod_prior,Nod_prioritate &x)
  140. {
  141. onod_prior << x.info;
  142. onod_prior << x.prio;
  143. return onod_prior;
  144. }
  145.  
  146.  
  147.  
  148. class Coada_prioritati: protected Nod_prioritate {
  149. protected:
  150. Nod_prioritate * nod_prim;
  151. Nod_prioritate * nod_final;
  152. public:
  153. Coada_prioritati()
  154. {
  155. info = 0;
  156. ante = NULL;
  157. next = NULL;
  158. prio = 0;
  159. nod_prim = NULL;
  160. nod_final = NULL;
  161. }
  162. Coada_prioritati(int infor, int prior)
  163. {
  164. info = infor;
  165. ante = NULL;
  166. next = NULL;
  167. prio = prior;
  168. nod_prim = NULL;
  169. nod_final = NULL;
  170. }
  171. void adaugare_nod(int x,int y)
  172. {
  173. Nod_prioritate *r = new Nod_prioritate;
  174. r->info = x;
  175. r->prio = y;
  176. r->next = NULL;
  177.  
  178. if (nod_prim == NULL)
  179. {
  180. nod_prim = r;
  181. nod_final = r;
  182. }
  183. else
  184. {
  185. Nod_prioritate * auxx=nod_prim;
  186. int ok = 1;
  187. while(ok == 1)
  188. {
  189.  
  190. if(r->prio > auxx->prio)
  191. {
  192. r->next = auxx;
  193. r->ante = auxx->ante;
  194. auxx->ante = r;
  195. if(auxx == nod_prim)
  196. nod_prim = r;
  197. ok = 0;
  198.  
  199. }
  200. else
  201. aux=aux->next;
  202. }
  203.  
  204. }
  205. }
  206. ~Coada_prioritati();
  207. friend istream& operator>>(istream &icoada,Coada_prioritati &x);
  208. friend ostream& operator<<(ostream &ocoada,Coada_prioritati &x);
  209. };
  210.  
  211. istream& operator>>(istream & icoada,Coada_prioritati &x)
  212. {
  213. icoada >> x.info;
  214. icoada >>x.prio;
  215. return icoada;
  216. }
  217.  
  218. ostream& operator<<(ostream &ocoada,Coada_prioritati &x)
  219. {
  220. ocoada << x.info;
  221. ocoada << x.prio;
  222. return ocoada;
  223. }
  224.  
  225.  
  226.  
  227.  
  228. class Coada_simpla : protected Coada prioritati{
  229. public:
  230. Coada_simpla()
  231. {
  232. info = 0;
  233. ante = NULL;
  234. next = NULL;
  235. prio = 0;
  236. nod_prim = NULL;
  237. nod_final = NULL;
  238. }
  239. Coada_simpla(int infor, int prior)
  240. {
  241. info = infor;
  242. ante = NULL;
  243. next = NULL;
  244. prio = prior;
  245. nod_prim = NULL;
  246. nod_final = NULL;
  247. }
  248. ~Coada_simpla()
  249. friend istream& operator>>(istream &icoada2,Coada_simpla &x);
  250. friend ostream& operator<<(ostream &ocoada2,Coada_simpla &x);
  251. };
  252.  
  253. istream& operator>>(istream & icoada2,Coada_simpla &x)
  254. {
  255. icoada2 >> x.info;
  256. icoada2 >> x.prio;
  257. return icoada2;
  258. }
  259.  
  260. ostream& operator<<(ostream &ocoada,Coada_prioritati &x)
  261. {
  262. ocoada2 << x.info;
  263. ocoada2 << x.prio;
  264. return ocoada2;
  265. }
  266.  
  267.  
  268. int main()
  269. {
  270.  
  271. return 0;
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement