Guest User

Untitled

a guest
Jun 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct pacijent{
  5. int matbr;
  6. int dob;
  7. };
  8.  
  9. struct tpacijenti{
  10. pacijent pacijenti[300];
  11. int kursor;
  12. };
  13.  
  14. void InitL(tpacijenti *lista){
  15. lista->kursor=0;
  16. }
  17.  
  18. int FirstL(tpacijenti *lista){
  19. return 0;
  20. }
  21.  
  22. int EndL(tpacijenti *lista){
  23. return lista->kursor;
  24. }
  25.  
  26. int NextL(int p, tpacijenti *lista){
  27. if(p==lista->kursor-1) return EndL(lista);
  28. if (p>=lista->kursor) cout << "Greska lista nije definirana"<<endl;
  29. else{
  30. cout << "Maticni broj pacijenta "<<lista->pacijenti[p+1].matbr;
  31. cout << "Dob pacijenta "<<lista->pacijenti[p+1].dob;
  32. }
  33. }
  34.  
  35. void PreviousL(int p, tpacijenti *lista){
  36. if(p==lista->kursor) {
  37. cout << "Maticni broj pacijenta "<<lista->pacijenti[lista->kursor-1].matbr;
  38. cout << "Dob pacijenta "<<lista->pacijenti[lista->kursor-1].dob;
  39. }
  40. else{
  41. if (p<=0 || p>lista->kursor) cout << "Greska lista nije definirana"<<endl;
  42. else{
  43. cout << "Maticni broj pacijenta "<<lista->pacijenti[p-1].matbr;
  44. cout << "Dob pacijenta "<<lista->pacijenti[p-1].dob;
  45. }
  46. }
  47. }
  48.  
  49. int LocateL(int x, tpacijenti *lista){
  50. for (int i=0;i<lista->kursor;i++){
  51. if (lista->pacijenti[i].matbr==x) return i;
  52. }
  53. return EndL(lista);
  54. }
  55. void InsertL(pacijent x, int p, tpacijenti *lista){
  56. if(p>=0 && p<=lista->kursor){
  57. lista->kursor++;
  58. for (int i=lista->kursor-1;i>=p;i--){
  59. lista->pacijenti[i]=lista->pacijenti[i-1];
  60. }
  61. lista->pacijenti[p]=x;
  62. }
  63. else cout << "Niste unijeli dobru poziciju"<<endl;
  64. }
  65.  
  66. void Insert(pacijent x, tpacijenti *lista){
  67.  
  68. lista->pacijenti[lista->kursor]=x;
  69. lista->kursor++;
  70. }
  71. void DeleteL(int p, tpacijenti *lista){
  72. if(p>=0 && p<=lista->kursor){
  73. for (int i=p;i<lista->kursor-1;i++){
  74. lista->pacijenti[i]=lista->pacijenti[i+1];
  75. }
  76. lista->kursor--;
  77. }
  78. else cout << "Niste unijeli dobru poziciju"<<endl;
  79. }
  80.  
  81. pacijent RetrieveL(int p, tpacijenti *lista){
  82. if (p<0 || p>=lista->kursor) cout << "Krivo unesena pozicija"<<endl;
  83. else return lista->pacijenti[p];
  84. }
  85.  
  86. void DeleteAllL(tpacijenti *lista){
  87. lista->kursor=0;
  88. }
  89.  
  90. void sort(tpacijenti *lista){
  91. for (int i=1; i<lista->kursor; i++){
  92. int j=i-1;
  93. pacijent pom=lista->pacijenti[i];
  94. while(j>=0 && lista->pacijenti[j].matbr>pom.matbr)
  95. lista->pacijenti[j+1]=lista->pacijenti[j--];
  96. lista->pacijenti[j+1]=pom;
  97. }
  98. }
  99.  
  100.  
  101.  
  102. void ispis(tpacijenti *lista){
  103. for(int i=0;i<lista->kursor;i++){
  104. cout << "Maticni broj je "<<lista->pacijenti[i].matbr<<endl;
  105. cout << "Dob je "<<lista->pacijenti[i].dob<<endl;
  106. cout <<"-------------------"<<endl;
  107. }
  108.  
  109. }
  110.  
  111. void ispisgodine(tpacijenti *lista){
  112. int brojac=0;
  113. for (int i=0;i<lista->kursor;i++){
  114. if (lista->pacijenti[i].dob<18){
  115. cout << "Maticni broj: "<<lista->pacijenti[i].matbr<<endl;
  116. cout << "Dob: "<<lista->pacijenti[i].dob<<endl;
  117. cout << "----------------"<<endl;
  118. brojac++;
  119. }
  120. }
  121. cout << "Mladih od 18 ima "<<brojac<<endl;
  122. }
  123.  
  124. int Delete(tpacijenti *lista, int matbr){
  125. for (int i=0;i<lista->kursor;i++){
  126. if(lista->pacijenti[i].matbr==matbr){
  127. for (int j=i;j<lista->kursor-1;j++){
  128. lista->pacijenti[j]=lista->pacijenti[j+1];
  129. }
  130. lista->kursor--;
  131. return 1;
  132. }
  133. }
  134. return 0;
  135. }
Add Comment
Please, Sign In to add comment