Guest User

Untitled

a guest
May 21st, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. // StogPoljem.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. #define MAXSTOG 5 // maksimalna velicina stoga
  7.  
  8. /*int dodaj (int stog[], int) {
  9. if (*vrh >= n-1) return 0; // dosegnut kapacitet stoga n
  10. (*vrh)++; // ne pisati *vrh++;
  11. stog[*vrh] = stavka;
  12. return 1;
  13. }
  14. int skini (int *stavka, int Stog[], int *vrh) {
  15. if (*vrh < 0) return 0; // stog je prazan
  16. *stavka = Stog[*vrh];
  17. (*vrh)--;
  18. return 1;
  19. }*/
  20.  
  21. int QuickSortIter(int polje[], int lijevo, int desno) {
  22.  
  23. int i;
  24. int j;
  25. StackPush(stog, desno);
  26. StackPush(stog, lijevo);
  27. while(!StackEmpty(stog)) {
  28. lijevo = StackTop(stog), StackPop(stog);
  29. desno = StackTop(stog), StackPop(stog);
  30. j= Partition(polje, lijevo, desno);
  31. if (lijevo < (j-1) ) {
  32. StackPush(stog, j-1);
  33. StackPush(stog, desno);
  34. }
  35. if ( (j+1) < desno ) {
  36. StackPush(stog, desno);
  37. StackPush(stog, j+1);
  38. }
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. int main () {
  46. int stog [MAXSTOG];
  47.  
  48.  
  49. }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. int Partition(int polje[], int lijevo, int desno) {
  57. int i;
  58. int j;
  59. int pivot;
  60. pivot = polje[lijevo];
  61. i = lijevo +1;
  62. j = desno;
  63. while(i<=j) {
  64.  
  65. while (polje[i] <= pivot && i <= desno)
  66. i+=1;
  67. while (polje[j] > pivot && j > lijevo)
  68. j-=1;
  69.  
  70. if (i<j)
  71. zamjeni (polje[i], polje[j]);
  72. zamjeni (polje[j], polje[lijevo];
  73. return j;
  74.  
  75. }
  76.  
  77. }
  78. return 0;
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. /*int StogPush(SP *s,ElementType *e)
  87. {
  88. if(s->Vrh < 99)
  89. {
  90. s->Vrh = s->Vrh +1;
  91. strcpy(s->Elements[s->Vrh].Ime,e->Ime);
  92. strcpy(s->Elements[s->Vrh].Prezime,e->Prezime);
  93. s->Elements[s->Vrh].b1=e->b1;
  94. s->Elements[s->Vrh].b2=e->b2;
  95. return 1;
  96. }
  97. else
  98. {
  99. printf("\nStog prepunjen");
  100. return 0;
  101. }
  102. }
  103. int StogPull(SP *s,ElementType *e)
  104. {
  105. if(s->Vrh >0)
  106. {
  107. s->Vrh=s->Vrh -1;
  108. strcpy(e->Ime,s->Elements[s->Vrh].Ime);
  109. strcpy(e->Prezime,s->Elements[s->Vrh].Prezime);
  110. e->b1=s->Elements[s->Vrh].b1;
  111. e->b2=s->Elements[s->Vrh].b2;
  112. return 1;
  113. }
  114.  
  115. void StogNew(SP *s)
  116. {
  117. s->Vrh=-1;
  118. int pos;
  119. for(pos=0;pos<100;pos++){
  120. strcpy(s->Elements[pos].Ime,"nemaIMe");
  121. strcpy(s->Elements[pos].Prezime,"nemaPrezime");
  122. s->Elements[pos].b1=0;
  123. s->Elements[pos].b2=0;
  124. }
  125. }
  126.  
  127. */
Add Comment
Please, Sign In to add comment