Posted By


majcen555 on 11/12/12

Tagged


Statistics


Viewed 144 times
Favorited by 0 user(s)

SP_Zadatak1_lista_polje_mm


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

Lista polje


Copy this code and paste it in your HTML
  1. struct tdatum {
  2. int dan;
  3. int godina;
  4. int mjesec;
  5. };
  6.  
  7. struct objekt {
  8. int sifra;
  9. char vrsta[30];
  10. char naziv[30];
  11. tdatum datum;
  12. float cijena;
  13. };
  14.  
  15. struct lis {
  16. objekt zivotinja[10000];
  17. int cursor;
  18. };
  19.  
  20. lis LA;
  21. int sifra=1,br_objekt=0,v=0;
  22.  
  23. void InitL(lis& LA) {
  24. LA.cursor=0;
  25. }
  26.  
  27. void InsertL(objekt x,int p,lis& LA) {
  28. LA.zivotinja[p]=x;
  29. LA.cursor++;
  30. }
  31.  
  32. objekt RetrieveL(int p,lis& LA) {
  33. return LA.zivotinja[p];
  34. }
  35.  
  36. int EndL(lis& LA) {
  37. return LA.cursor;
  38. }
  39.  
  40. int LocateL(char x[], lis& LA) {
  41. int p = EndL(LA);
  42. bool lociran=0;
  43. for(int i=0;i<p;i++)
  44. if(!strcmp(LA.zivotinja[i].naziv,x)||
  45. !strcmp(LA.zivotinja[i].vrsta,x)) {
  46. lociran=1;
  47. return i;
  48. }
  49. if(!lociran) return p;
  50. }
  51.  
  52. void DeleteL(int p,lis& LA) {
  53. if(p==EndL(LA)-1) LA.cursor--;
  54. else {
  55. for(int i=p;i<EndL(LA)-1;i++)
  56. LA.zivotinja[i]=LA.zivotinja[i+1];
  57. LA.cursor--;
  58. }
  59. }
  60.  
  61. int FirstL(lis& LA) {
  62. if(EndL(LA)==0) return EndL(LA);
  63. return 0;
  64. }
  65.  
  66. int PreviousL(int p,lis& LA) {
  67. if(p==FirstL(LA)) return -1;
  68. return p-1;
  69. }
  70.  
  71. int NextL(int p,lis& LA) {
  72. if(p==EndL(LA)) return -1;
  73. if(p==EndL(LA)-1) return EndL(LA);
  74. return p+1;
  75. }
  76.  
  77. void DeleteAll(lis& LA) {
  78. LA.cursor=0;
  79. }

URL: http://e.foi.hr/wiki/strukture_podataka/index.php/Zadatak_1_Majcen_Marko

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.