Posted By


mdino on 11/10/12

Tagged


Statistics


Viewed 62 times
Favorited by 0 user(s)

lista_polja_mdino


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

Biblioteka lista_polja


Copy this code and paste it in your HTML
  1. //implementacija pomocu polja
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. struct t_zivotinja {
  6. int sifra,dan,mjesec,godina;
  7. char naziv[40];
  8. char vrsta[40];
  9. float cijena;
  10. };
  11.  
  12. struct t_sve_zivotinje {
  13. t_zivotinja*element[1000];
  14. int kursor;
  15. };
  16.  
  17. int FirstL(t_sve_zivotinje*lista) {
  18. return 0;
  19. }
  20.  
  21. int EndL(t_sve_zivotinje*lista) {
  22. return lista->kursor;
  23. }
  24.  
  25. int NextL(int k,t_sve_zivotinje*lista) {
  26. return k+1;
  27. }
  28.  
  29. int PreviousL(int k,t_sve_zivotinje*lista) {
  30. return k-1;
  31. }
  32.  
  33. int LocateL(int n,t_sve_zivotinje*lista) {
  34. for(int i=0; i<lista->kursor; i++) {
  35. if(n==lista->element[i]->sifra)return i;
  36. }
  37. return lista->kursor; //endL
  38. }
  39. void InsertL(t_zivotinja*novi, int k, t_sve_zivotinje*lista) {
  40. if(k>EndL(lista))
  41. cout<<"Prevelika pozicija!\n";
  42.  
  43. else {//<=endl
  44. for (int i = EndL(lista); i > k; i--) {
  45. lista->element[i] = lista->element[i-1];
  46. }
  47. lista->element[k] = novi;
  48. lista->kursor = lista->kursor + 1;
  49. }
  50. }
  51. int DeleteL(int k, t_sve_zivotinje*lista) {
  52. k-=1;
  53. if(k>EndL(lista))
  54. cout<<"Taj element ne postoji!\n";
  55. else {
  56. for(int i=k; i<EndL(lista); i++) {
  57. lista->element[i]=lista->element[i+1];
  58. }
  59. lista->kursor=lista->kursor-1;
  60. return 0;
  61. }
  62. }
  63.  
  64. void DeleteAll(t_sve_zivotinje*lista) {
  65. lista->kursor=0;
  66. }
  67.  
  68. int NumberL(t_sve_zivotinje*lista) {
  69. int k=lista->kursor;
  70. return k;
  71. }
  72.  
  73. t_zivotinja*RetrieveL(int k,t_sve_zivotinje*lista) {
  74. return lista->element[k-1];
  75. }
  76.  
  77. t_sve_zivotinje*InitL(t_sve_zivotinje*lista) {
  78. t_sve_zivotinje*novi=new t_sve_zivotinje;
  79. novi->kursor=0;
  80. return novi;
  81. }
  82.  
  83. t_zivotinja*UnosL(t_zivotinja*novi) {
  84. cout<<"Sifra= ";
  85. cin>>novi->sifra;
  86. cout<<"Vrsta= ";
  87. cin>>novi->vrsta;
  88. cout<<"Naziv= ";
  89. cin>>novi->naziv;
  90. cout<<"Cijena= ";
  91. cin>>novi->cijena;
  92. do {
  93. cout<<"Dan dostave= ";
  94. cin>>novi->dan;
  95. }
  96. while(novi->dan<1||novi->dan>32);
  97. do {
  98. cout<<"Mjesec dostave= ";
  99. cin>>novi->mjesec;
  100. }
  101. while(novi->mjesec<1||novi->mjesec>12);
  102. cout<<"Godina dostave= ";
  103. cin>>novi->godina;
  104. }
  105.  
  106. t_zivotinja*IspisL(t_zivotinja*novi) {
  107. cout<<"=====================\n";
  108. cout<<"Zivotinja\n";
  109. cout<<"---------------------\n";
  110. cout<<"Sifra= "<<novi->sifra<<endl;
  111. cout<<"Vrsta= "<<novi->vrsta<<endl;
  112. cout<<"Naziv= "<<novi->naziv<<endl;
  113. cout<<"Datum= "<<novi->dan<<"."<<novi->mjesec<<"."<<novi->godina<<endl;
  114. cout<<"Cijena= "<<novi->cijena<<endl;
  115. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.