Guest User

Untitled

a guest
Jun 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. using namespace std;
  2.  
  3. struct pac {
  4. int mbr, god;
  5. char ime[20], prez [25];
  6. }p;
  7.  
  8. struct lista {
  9. pac P [50];
  10. int end;
  11. }L;
  12.  
  13. int FirstL(lista *L) {
  14. return 0;
  15. };
  16.  
  17.  
  18. int EndL(lista *L) {
  19.  
  20. return L->end;
  21. };
  22.  
  23. int NextL(int p, lista *L) {
  24. if(L->end == 0) {
  25. cout << "Lista je prazna" << endl;
  26. return 0;
  27. }
  28.  
  29. else {
  30. int i;
  31. i = p + 1;
  32. return i;}
  33. };
  34.  
  35. int PreviousL(int p, lista *L) {
  36. if(L->end == 0) {
  37. cout << "Lista je prazna" << endl;
  38. return 0;
  39. }
  40. else{
  41. int i;
  42. i = p - 1;
  43. return i;}
  44. };
  45. int LocateL(int x, lista *L) {
  46. if(L->end == 0) {
  47. cout << "Lista je prazna" << endl;
  48. return 0;
  49. }
  50. else {
  51. int i;
  52. i = 0;
  53. while((i != L->end) && (L->P[i].mbr != x))
  54. i++;
  55. return i;}
  56. };
  57.  
  58. int InsertL(pac x, int p, lista *L) {
  59. int i;
  60. if(L->end == 50) {
  61. cout << "Lista je puna" << endl;
  62. return 0;
  63. }
  64.  
  65. else {
  66.  
  67. L->P[p].mbr = x.mbr;
  68. L->P[p].god = x.god;
  69. strcpy(L->P[p].ime, x.ime);
  70. strcpy(L->P[p].prez, x.prez);
  71. L->end++;
  72. return 1;
  73. }
  74. };
  75.  
  76. int DeleteL(int p, lista *L) {
  77. int izb = 0, bmbr, bpoz;
  78. cout << "Upisite Maticni broj pacijenta kojeg zelite obrisati: " ;
  79. cin >> bmbr;
  80.  
  81. if(L->end == 0) {
  82. cout<<"Lista je prazna"<<endl;
  83. return 0; }
  84.  
  85. int end = EndL(L);
  86.  
  87. while (p < end){
  88. if (L->P[p].mbr == bmbr) {
  89. bpoz = p;
  90. izb = 1;}
  91. p++;}
  92. if(izb == 1){
  93. for(int i = bpoz; i < L->end; i++) L->P [i] = L->P[i+1];
  94. L->end--;
  95. return 1;}
  96. else {
  97. cout << "Pacijent s upisanim maticnim brojem ne postoji" << endl;
  98. return 0; }
  99. };
  100.  
  101.  
  102. pac RetrieveL(int p, lista *L) {
  103. if(L->end == 0) {
  104. cout << "Lista je prazna" << endl;
  105. exit(0);
  106. }
  107.  
  108. else {
  109. return(L->P[p]);}
  110. };
  111.  
  112. void DeleteAllL(lista *L) {
  113. L->end = 0;
  114. };
  115.  
  116. void sort (lista *L){
  117. int pom;
  118. lista PL;
  119. int n = EndL(L);
  120. for (int i = 0; i < n; i++){
  121. PL.P[i] = L->P[i];}
  122.  
  123. for (int i = 1; i < n; i++){
  124. int j = i - 1;
  125. int pom = L->P[i].mbr;
  126. while (j >= 0 && L->P[j].mbr > pom){
  127. L->P[j+1].mbr = L->P[j--].mbr;}
  128. L->P[j+1].mbr = pom;}
  129.  
  130. for (int i = 0; i < n; i++){
  131. for (int j = 0; j < n; j++){
  132. if (L->P[i].mbr == PL.P[j].mbr) L->P[i] = PL.P[j];}}
  133. };
  134.  
  135. int pret (lista *L){
  136. int n = EndL(L);
  137. int br = 0;
  138. for (int i = 0; i < n; i++){
  139. if (L->P[i].god < 18){
  140. cout << endl << "Maticni broj: " << L->P[i].mbr << endl;
  141. cout << "Ime: " << L->P[i].ime << endl;
  142. cout << "Prezime: " << L->P[i].prez << endl;
  143. cout << "Godine: " << L->P[i].god << endl;
  144. br++;}}
  145. return br;
  146. };
  147.  
  148. void isp(lista *L){
  149. int pos = FirstL(L);
  150. int poss = EndL(L);
  151. cout << "--Ispis sadrzaja liste od najmanjeg maticnog broja--" << endl;
  152. cout << "----------------------------------------------------" ;
  153. while (pos < poss && pos >= 0){
  154. cout << endl << "Maticni broj: " << L->P[pos].mbr << endl;
  155. cout << "Ime: " << L->P[pos].ime << endl;
  156. cout << "Prezime: " << L->P[pos].prez << endl;
  157. cout << "Godine: " << L->P[pos].god << endl;
  158. pos++;}
  159. };
Add Comment
Please, Sign In to add comment