Posted By


fijelicic1 on 11/12/12

Tagged


Statistics


Viewed 71 times
Favorited by 0 user(s)

implementacija_pomoću_polja


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

implementacija liste pomoću polja


Copy this code and paste it in your HTML
  1. struct zivotinja {
  2.  
  3. int sifra;
  4. float cijena;
  5. char naziv[50];
  6. char vrsta[50];
  7. int d,m,y;
  8.  
  9. };
  10.  
  11. struct lista {
  12. zivotinja popis[1000];
  13. int kursor;
  14. };
  15.  
  16. typedef lista list;
  17. typedef int element;
  18.  
  19. element FirstL(list *L){
  20. return 0;
  21. }
  22.  
  23. element EndL(list *L){
  24. return L->kursor;
  25. }
  26.  
  27. void InitL(list *L){
  28. L->kursor = 0;
  29. }
  30.  
  31. element NextL(element e, list *L){
  32. return e+1;
  33. }
  34.  
  35. element PreviousL(element e, list*L){
  36. return e-1;
  37. }
  38.  
  39. element LocateL(zivotinja z, list *L){
  40. int i;
  41. for(int i = 0; i<L->kursor; i++){
  42. if(z.sifra == L->popis[i].sifra){
  43. return i;
  44. }
  45.  
  46. else{
  47. return EndL(L);
  48. }}
  49. }
  50.  
  51. void InsertL(zivotinja z, element e, list *L){
  52. int i;
  53. for(i = EndL(L); i>e; i--){
  54. L->popis[i] = L->popis[i-1];
  55. }
  56. L->popis[e] = z;
  57. L->kursor = L->kursor +1;
  58. }
  59.  
  60. zivotinja RetrieveL(element e, list *L){
  61. return L->popis[e];
  62. }
  63.  
  64. void DeleteL(element e, list *L){
  65. int i;
  66. for(i=e; i< EndL(L); i++){
  67. L->popis[i] = L->popis[i+1];
  68. }
  69. L->kursor = L->kursor -1;
  70. }
  71.  
  72. void DelleteAllL(list *L){
  73. L->kursor = 0;
  74. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.