Guest User

Untitled

a guest
Jun 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. // datoteka zaglavlja za implementaciju liste pomocu polja
  2.  
  3. #include<iostream>
  4. using namespace std;
  5.  
  6. struct tpacijent {
  7. int JMBG;
  8. char ime[50];
  9. int starost;
  10. };
  11.  
  12. struct lista {
  13. tpacijent values[1000];
  14. int cursor;
  15. };
  16.  
  17. lista pacijenti;
  18.  
  19. int EndL(lista L) {
  20. return L.cursor;
  21. }
  22.  
  23. int FirstL(lista L) {
  24. if(L.cursor != 0) return 0;
  25. else return EndL(L);
  26. }
  27.  
  28. int NextL(int p, lista L) {
  29. if(p == (EndL(L) - 1)) return EndL(L);
  30. else return p+1;
  31. }
  32.  
  33. int PreviousL(int p, lista L) {
  34. if(p == FirstL(L)) return EndL(L);
  35. else return p-1;
  36. }
  37.  
  38. int LocateL(int p, lista L) {
  39. int a = 0;
  40. while(a != EndL(L)) {
  41. if(L.values[a].JMBG == p) return a;
  42. a++;
  43. }
  44. return EndL(L);
  45. }
  46.  
  47. void InsertL(tpacijent pacijent, int p, lista &L) {
  48. int a = EndL(L);
  49. L.cursor++;
  50. while(1) {
  51. L.values[a] = L.values[a-1];
  52. if(a == p) {
  53. L.values[p] = pacijent;
  54. return;
  55. }
  56. a--;
  57. }
  58. }
  59.  
  60. void DeleteL(int p, lista &L) {
  61. while(p < (EndL(L) - 1)) {
  62. L.values[p] = L.values[p+1];
  63. p++;
  64. }
  65. L.cursor--;
  66. }
  67.  
  68.  
  69. tpacijent RetrieveL(int p, lista L) {
  70. return L.values[p];
  71. }
  72.  
  73. void DeleteAll(lista &L) {
  74. L.cursor = 0;
  75. }
  76.  
  77. void InitL(lista &L) {
  78. L.cursor = 0;
  79. }
Add Comment
Please, Sign In to add comment