Posted By

ivadobrincic1 on 11/11/12


Tagged

lista implementacija funkcije


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ivadobrincic1


Lista_polje.h


 / Published in: C++
 

Implementacija liste pomocu polja.

  1. #include <string>
  2. using namespace std;
  3.  
  4.  
  5. struct animal {
  6. int sifra;
  7. string naziv;
  8. string vrsta;
  9. string datum;
  10. int cijena;
  11. };
  12.  
  13. struct List {
  14. animal polje[10000];
  15. int kursor;
  16. };
  17.  
  18. typedef List Lista;
  19. typedef int element;
  20.  
  21. void InitL(Lista *list) {
  22. list->kursor = 0;
  23. }
  24.  
  25. element FirstL(Lista *list) {
  26. return 0;
  27. }
  28.  
  29. element EndL(Lista *list) {
  30. return list->kursor;
  31. }
  32.  
  33. element NextL(element e, Lista *list) {
  34. return e+1;
  35. }
  36.  
  37. element PreviousL(element e, Lista *list) {
  38. return e-1;
  39. }
  40.  
  41. int InsertL(animal nova_z, element e, Lista *list) {
  42.  
  43. if (list->kursor == 10000) {
  44. return 0;
  45. }
  46.  
  47. for (int i = list->kursor; i > e; i--) {
  48. list->polje[i] = list->polje[i-1];
  49. }
  50. list->polje[e] = nova_z;
  51. list->kursor++;
  52. return 1;
  53. }
  54.  
  55. bool DeleteL(element e, Lista *list) {
  56. for (int i = e; i < list->kursor; i++) {
  57. list->polje[i] = list->polje[i+1];
  58. }
  59. list->kursor--;
  60. }
  61.  
  62. void DeleteAll(Lista *list) {
  63. list->kursor = 0;
  64. }
  65.  
  66. animal RetrieveL(element e, Lista *list) {
  67. return list->polje[e];
  68. }
  69.  
  70. element LocateL(animal odbjegla, Lista *list) {
  71. for (int i = 0; i < list->kursor; i++) {
  72. if (list->polje[i].sifra == odbjegla.sifra) {
  73. return i;
  74. }
  75. }
  76.  
  77. }

Report this snippet  

You need to login to post a comment.