Advertisement
PopaLepo

Alocarea dinamica a memoriei

May 29th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. STIVA :
  2.  
  3. struct nods{ int inf; nods*ant;};
  4. nods *vf;
  5.  
  6. void adauga(nods *&vf, int x)
  7. {
  8. if(vf==NULL)
  9. {
  10. vf=new nods;
  11. vf->inf=x;
  12. vf->ant=NULL;
  13. }
  14. else
  15. {
  16. nods *nou;
  17. nou=new nods;
  18. nou->inf=x;
  19. nou->ant=vf;
  20. vf=nou;
  21. }
  22. }
  23.  
  24. void parcurge(nods *vf)
  25. {
  26. nods *p;
  27. p=vf;
  28. while(p!=NULL)
  29. {
  30. // prelucram p->inf
  31. p=p->ant;
  32. }
  33. }
  34.  
  35. void sterge(nods *vf)
  36. {
  37. nods *p;
  38. p=vf;
  39. vf=vf->ant;
  40. delete p;
  41. }
  42.  
  43. COADA :
  44.  
  45. struct nodc{ int inf; nodc*urm;};
  46. nodc *prim,*ultim;
  47.  
  48. void adauga(nodc *&prim, nodc *&ultim, int x)
  49. {
  50. if(prim==NULL)
  51. {
  52. prim=new nodc;
  53. prim->inf=x;
  54. prim->urm=NULL;
  55. ultim=prim;
  56. }
  57. else
  58. {
  59. nodc *nou;
  60. nou=new nodc;
  61. nou->inf=x;
  62. nou->urm=NULL;
  63. ultim->urm=nou;
  64. ultim=nou;
  65. }
  66. }
  67.  
  68. void parcurge(nodc *prim)
  69. {
  70. nodc *p;
  71. p=prim;
  72. while(p!=NULL)
  73. {
  74. // prelucram p->inf
  75. p=p->urm;
  76. }
  77. }
  78.  
  79. void sterge(nodc *&prim, nodc *&ultim)
  80. {
  81. nodc *p;
  82. p=prim;
  83. prim=prim->urm;
  84. delete p;
  85. }
  86.  
  87. LISTA SIMPLU INLANTUITA :
  88.  
  89. struct nodl{ int inf; nodl*urm;};
  90. nodc *prim,*ultim;
  91.  
  92. void adauga(nodl *&prim, nodl*&ultim, int x)
  93. {
  94. if(prim==NULL)
  95. {prim=new nodl;
  96. prim->inf=x;
  97. prim->urm=NULL;
  98. ultim=prim;}
  99. else
  100. {nodl *nou;
  101. nou->inf=x;
  102. nou->urm=NULL;
  103. ultim->urm=nou;
  104. ultim=nou;}
  105. }
  106.  
  107. LISTA DUBLU INALNTUITA :
  108.  
  109. struct nodd{ int inf; nodd*urm,*ant;};
  110. nodd *prim,*ultim;
  111.  
  112. void adauga(nodd *&prim, nodd*&ultim, int x)
  113. {
  114. if(prim==NULL)
  115. {prim=new nodd;
  116. prim->inf=x;
  117. prim->ant=NULL;
  118. prim->urm=NULL;
  119. ultim=prim;}
  120. else
  121. {nodd *nou;
  122. nou->inf=x;
  123. nou->urm=NULL;
  124. nou->ant=ultim;
  125. ultim->urm=nou;
  126. ultim=nou;}
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement