Posted By

mhudince on 11/10/12


Tagged

merge mario pokazivaci c++ zivotinje sortiranje zaglavlja hudincec


Versions (?)

Strukture_podataka_zad_1 (lista_polje.h)


 / Published in: C++
 

URL: mhudince2

zadatak za Sp

  1. #include <cstring>
  2.  
  3. struct zivotinje {
  4. int sifra, cijena, d, m, g;
  5. char naziv [20], vrsta [30];
  6. };
  7.  
  8. zivotinje ziv;
  9.  
  10. struct LIST {
  11. int sifra[1000], cijena[1000], d[1000], m[1000], g[1000];
  12. char naziv [20][1000], vrsta [30][1000];
  13. int pointer;
  14. };
  15.  
  16. typedef int element;
  17.  
  18. element ENDL (LIST *L) {
  19. return L->pointer;
  20. }
  21.  
  22. element FIRSTL (LIST *L) {
  23. if (L->pointer == 0) ENDL(L);
  24. return 0;
  25. }
  26.  
  27. element NEXTL (element position, LIST *L) {
  28. if ((position >= L->pointer) || (position < 0))
  29. return 0;
  30. return(position + 1);
  31. }
  32.  
  33. element PREVIOUSL (element position, LIST *L) {
  34. if ((position > L->pointer) || (position <= 0))
  35. return (position - 1);
  36. }
  37.  
  38. element LOCATEL (zivotinje z, LIST *L) {
  39. int br = 0;
  40. while ((br != L->pointer) && (L->sifra[br]!= z.sifra))
  41. br ++;
  42. return br;
  43. }
  44.  
  45. element INSERTL (zivotinje z, element position, LIST *L) {
  46. int br;
  47. if ((position <= L->pointer) && (position >= 0)) {
  48. for (br=L->pointer; br >= position; br --) {
  49. L->sifra[br] = L->sifra[br-1];
  50. L->cijena[br] = L->cijena[br-1];
  51. L->d[br] = L->d[br-1];
  52. L->m[br] = L->m[br-1];
  53. L->g[br] = L->g[br-1];
  54. strcpy (L->naziv[br],L->naziv[br-1]);
  55. strcpy (L->vrsta[br],L->vrsta[br-1]);
  56. }
  57. L->pointer ++;
  58. L->sifra[position] = z.sifra;
  59. L->cijena[position] = z.cijena;
  60. L->d[position] = z.d;
  61. L->m[position] = z.m;
  62. L->g[position] = z.g;
  63. strcpy (L->naziv[position],z.naziv);
  64. strcpy (L->vrsta[position],z.vrsta);
  65. return 1;
  66. }
  67. else
  68. return 0;
  69. }
  70.  
  71. element DELETEL (element position, LIST *L) {
  72. int br;
  73. if ((position < L->pointer) && (position >= 0)) {
  74. for (br = position; br < L->pointer; br ++){
  75. L->sifra[br] = L->sifra[br+1];
  76. L->cijena[br] = L->cijena[br+1];
  77. L->d[br] = L->d[br+1];
  78. L->m[br] = L->m[br+1];
  79. L->g[br] = L->g[br+1];
  80. strcpy(L->naziv[br],L->naziv[br+1]);
  81. strcpy(L->vrsta[br],L->vrsta[br+1]);
  82. }
  83. L->pointer --;
  84. return 1;
  85. }
  86. else
  87. return 0;
  88. }
  89.  
  90. zivotinje RETRIEVEL (element position, LIST *L) {
  91. if ((position < L->pointer) && (position >= 0)) {
  92. ziv.sifra = L->sifra[position];
  93. ziv.cijena = L->cijena[position];
  94. ziv.d = L->d[position];
  95. ziv.m = L->m[position];
  96. ziv.g = L->g[position];
  97. strcpy(ziv.naziv,L->naziv[position]);
  98. strcpy(ziv.vrsta,L->vrsta[position]);
  99. return ziv;
  100. }
  101. }
  102.  
  103. element DELETEALLL (LIST *L) {
  104. L->pointer = 0;
  105. return 0;
  106. }
  107.  
  108. LIST *INITL (LIST *L) {
  109. L = new LIST;
  110. L->pointer = 0;
  111. return L;
  112. }

Report this snippet  

You need to login to post a comment.