Posted By


dmacan23 on 11/12/12

Tagged


Statistics


Viewed 108 times
Favorited by 0 user(s)

Related snippets


Strukture_Podataka_Z1-lista_pokazivaci.cpp


/ Published in: C++
Save to your folder(s)

Zadatak kolegija "Strukture podataka" na Fakultetu Organizacije i Informatike u Varaždinu. Trebalo je napraviti program koji služi za evidenciju kućnih ljubimaca u trgovini za kućne ljubimce, i to pomoću ATP liste implementirane poljem i pokazivačima. Ovo je samo zaglavlje koje treba "glavna.cpp" kako bi radilo


Copy this code and paste it in your HTML
  1. /*
  2.  * lista_pokazivaci.h
  3.  *
  4.  * Created on: Nov 8, 2012
  5.  * Author: David Ante Macan
  6.  */
  7.  
  8. #ifndef LISTA_POKAZIVACI_H_
  9. #define LISTA_POKAZIVACI_H_
  10.  
  11. #include<iostream>
  12. using namespace std;
  13.  
  14. int provjera = 1;
  15.  
  16. struct tziv{
  17. int sifra;
  18. char vrsta[20];
  19. char naziv[20];
  20. float cijena;
  21. int datum[3];
  22. };
  23.  
  24. struct tlista{
  25. tziv ziv;
  26. tlista *kursor;
  27. };
  28.  
  29. typedef tlista *tip;
  30.  
  31.  
  32. tip FirstL(tlista *L){
  33. return L->kursor;
  34. }
  35.  
  36.  
  37. tip EndL(tlista *L){
  38. tlista *tekuci = L;
  39. while(tekuci->kursor){
  40. tekuci=tekuci->kursor;
  41. }
  42. return tekuci->kursor;
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. tip PreviousL(tip p, tlista *L){
  50. if(L->kursor==NULL)
  51. return L;
  52. tlista *prosli = L->kursor;
  53. while(prosli->kursor!=p){
  54. prosli=prosli->kursor;
  55. }
  56. return prosli;
  57. }
  58.  
  59.  
  60.  
  61. tip NextL(tip p, tlista *L){
  62. if(p->kursor==NULL)
  63. return EndL(L);
  64. return p->kursor;
  65. }
  66.  
  67.  
  68.  
  69. tlista *InitL(tlista *L){
  70. L = new tlista;
  71. L->kursor = NULL;
  72. return L;
  73. }
  74.  
  75.  
  76. tip LocateL(tziv x, tlista *L){
  77. tip tekuci;
  78. tekuci = L->kursor;
  79. while(tekuci){
  80. if(x.sifra!=0){
  81. if(x.sifra == tekuci->ziv.sifra)
  82. return tekuci;
  83. }
  84. }
  85. return EndL(L);
  86. }
  87.  
  88.  
  89. int InsertL(tziv x, tlista *p, tlista *L){
  90. tlista *novi = new tlista;
  91. tlista *prosli = PreviousL(p,L);
  92. if(p==EndL(L)){
  93. novi->kursor = NULL;
  94. prosli->kursor = novi;
  95. novi->ziv = x;
  96. }
  97. else{
  98. novi->kursor=prosli->kursor;
  99. prosli->kursor = novi;
  100. novi->ziv = x;
  101. }
  102. if(novi->ziv.sifra == x.sifra)
  103. return 1;
  104. else
  105. return 0;
  106. }
  107.  
  108. tziv RetrieveL(tip p, tlista *L){
  109. return p->ziv;
  110. }
  111.  
  112.  
  113. tip DeleteL(tip p, tlista *L){
  114. tlista *prethodni, *tekuci;
  115. tekuci=p;
  116. if(tekuci==EndL(L))return 0;
  117. if(p==FirstL(L)){
  118. L->kursor=tekuci->kursor;
  119. delete tekuci;
  120. return 0;
  121. }
  122. else{
  123. prethodni=PreviousL(tekuci,L);
  124. prethodni->kursor=tekuci->kursor;
  125. delete tekuci;
  126. return 0;
  127. }
  128. return 0;
  129. }
  130.  
  131.  
  132. tip DeleteAllL(tlista *L){
  133. tlista *tekuci = L->kursor;
  134. tlista *iduci;
  135. while(tekuci!=NULL){
  136. iduci = tekuci->kursor;
  137. delete tekuci;
  138. tekuci = iduci;
  139. }
  140. L->kursor = NULL;
  141. return 0;
  142. }
  143.  
  144.  
  145.  
  146. void Merge(tziv array[], int i, int k, int j){
  147. int pocetak = i, iduci = k+1, brojilo=0, velicina = j-i+1;
  148. tziv *pom = new tziv[velicina];
  149. while(pocetak<=k && iduci<=j){
  150. if(array[pocetak].cijena > array[iduci].cijena)
  151. pom[brojilo++]=array[pocetak++];
  152. else if(array[pocetak].cijena < array[iduci].cijena)
  153. pom[brojilo++] = array[iduci++];
  154. if(array[pocetak].cijena == array[iduci].cijena){
  155. if(strcmp(array[pocetak].naziv, array[iduci].naziv)==1)
  156. pom[brojilo++] = array[pocetak++];
  157. else
  158. pom[brojilo++] = array[iduci++];
  159. }
  160. }
  161.  
  162. while(pocetak<=k)
  163. pom[brojilo++] = array[pocetak++];
  164. while(iduci<=j)
  165. pom[brojilo++] = array[iduci++];
  166. for(int I=0; I<velicina; I++)
  167. array[i+I]=pom[I];
  168. delete[] pom;
  169. }
  170.  
  171. void funkcija(tziv array[], int i, int j){
  172. int sredina;
  173. if(i<j){
  174. sredina = (i+j)/2;
  175. funkcija(array,i,sredina);
  176. funkcija(array,sredina+1,j);
  177. Merge(array,i,sredina,j);
  178. }
  179. }
  180.  
  181. void MSort(tlista *L, tip i, tip j){
  182. if(FirstL(L)!=EndL(L)){
  183. int velicina = 0, brojilo = 0;
  184. tip zadnji;
  185. zadnji = L;
  186. while(zadnji->kursor){
  187. zadnji = zadnji->kursor;
  188. velicina++;
  189. }
  190. tziv *pom = new tziv[velicina];
  191. tip lokacija = L->kursor;
  192. while(lokacija){
  193. pom[brojilo++] = RetrieveL(lokacija,L);
  194. lokacija = lokacija->kursor;
  195. }
  196. funkcija(pom,0,velicina-1);
  197. for(int i=0; i<=velicina-1; i++){
  198. cout<<"\n\n"
  199. <<"Sifra zivotinje: "<<pom[i].sifra<<endl
  200. <<"Vrsta zivotinje: "<<pom[i].vrsta<<endl
  201. <<"Naziv zivotinje: "<<pom[i].naziv<<endl
  202. <<"Cijena zivotinje: "<<pom[i].cijena<<endl
  203. <<"Datum dostave: "<<pom[i].datum[2]<<"."<<pom[i].datum[1]<<"."<<pom[i].datum[0]<<"."<<endl
  204. <<"-------------------------------------"<<endl<<endl;
  205. }
  206. }
  207. else
  208. cout<<"Lista ne postoji ili je prazna"<<endl;
  209. }
  210.  
  211.  
  212. #endif /* LISTA_POKAZIVACI_H_ */

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.