Guest User

Untitled

a guest
May 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 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.     int stog [MAXSTOG];
  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.         pivot = polje[lijevo];
  60.         i = lijevo +1;
  61.         j = desno;
  62.         while(i<=j) {
  63.  
  64.             while (polje[i] <= pivot && i <= desno)
  65.                 i+=1;
  66.             while (polje[j] > pivot && j > lijevo)
  67.                 j-=1;
  68.  
  69.             if (i<j)    {
  70.                 zamjeni (polje[i], polje[j]);
  71.                 zamjeni (polje[j], polje[lijevo];
  72.  
  73.             return j;
  74.             }
  75.         }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.     }
  82.     return 0;
  83. }
  84.  
  85.    
  86.    
  87.    
  88.    
  89.    
  90.     /*int StogPush(SP *s,ElementType *e)
  91. {
  92.     if(s->Vrh < 99)
  93.     {
  94.         s->Vrh = s->Vrh +1;
  95.         strcpy(s->Elements[s->Vrh].Ime,e->Ime);
  96.         strcpy(s->Elements[s->Vrh].Prezime,e->Prezime);
  97.         s->Elements[s->Vrh].b1=e->b1;
  98.         s->Elements[s->Vrh].b2=e->b2;
  99.         return 1;
  100.     }
  101.     else
  102.     {
  103.         printf("\nStog prepunjen");
  104.         return 0;
  105.     }
  106. }
  107. int StogPull(SP *s,ElementType *e)
  108. {
  109.     if(s->Vrh >0)
  110.     {
  111.         s->Vrh=s->Vrh -1;
  112.         strcpy(e->Ime,s->Elements[s->Vrh].Ime);
  113.         strcpy(e->Prezime,s->Elements[s->Vrh].Prezime);
  114.         e->b1=s->Elements[s->Vrh].b1;
  115.         e->b2=s->Elements[s->Vrh].b2;
  116.         return 1;
  117.     }
  118.    
  119.     void StogNew(SP *s)
  120. {
  121.     s->Vrh=-1;
  122.     int pos;
  123.     for(pos=0;pos<100;pos++){
  124.         strcpy(s->Elements[pos].Ime,"nemaIMe");
  125.         strcpy(s->Elements[pos].Prezime,"nemaPrezime");
  126.         s->Elements[pos].b1=0;
  127.         s->Elements[pos].b2=0;
  128.     }
  129. }
  130.    
  131.     */
Add Comment
Please, Sign In to add comment