Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // StogPoljem.c
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define MAXSTOG 5 // maksimalna velicina stoga
- /*int dodaj (int stog[], int) {
- if (*vrh >= n-1) return 0; // dosegnut kapacitet stoga n
- (*vrh)++; // ne pisati *vrh++;
- stog[*vrh] = stavka;
- return 1;
- }
- int skini (int *stavka, int Stog[], int *vrh) {
- if (*vrh < 0) return 0; // stog je prazan
- *stavka = Stog[*vrh];
- (*vrh)--;
- return 1;
- }*/
- int QuickSortIter(int polje[], int lijevo, int desno) {
- int i;
- int j;
- StackPush(stog, desno);
- StackPush(stog, lijevo);
- while(!StackEmpty(stog)) {
- lijevo = StackTop(stog), StackPop(stog);
- desno = StackTop(stog), StackPop(stog);
- j= Partition(polje, lijevo, desno);
- if (lijevo < (j-1) ) {
- StackPush(stog, j-1);
- StackPush(stog, desno);
- }
- if ( (j+1) < desno ) {
- StackPush(stog, desno);
- StackPush(stog, j+1);
- }
- }
- int main () {
- int stog [MAXSTOG];
- }
- int Partition(int polje[], int lijevo, int desno) {
- int i;
- int j;
- int pivot;
- pivot = polje[lijevo];
- i = lijevo +1;
- j = desno;
- while(i<=j) {
- while (polje[i] <= pivot && i <= desno)
- i+=1;
- while (polje[j] > pivot && j > lijevo)
- j-=1;
- if (i<j)
- zamjeni (polje[i], polje[j]);
- zamjeni (polje[j], polje[lijevo];
- return j;
- }
- }
- return 0;
- }
- /*int StogPush(SP *s,ElementType *e)
- {
- if(s->Vrh < 99)
- {
- s->Vrh = s->Vrh +1;
- strcpy(s->Elements[s->Vrh].Ime,e->Ime);
- strcpy(s->Elements[s->Vrh].Prezime,e->Prezime);
- s->Elements[s->Vrh].b1=e->b1;
- s->Elements[s->Vrh].b2=e->b2;
- return 1;
- }
- else
- {
- printf("\nStog prepunjen");
- return 0;
- }
- }
- int StogPull(SP *s,ElementType *e)
- {
- if(s->Vrh >0)
- {
- s->Vrh=s->Vrh -1;
- strcpy(e->Ime,s->Elements[s->Vrh].Ime);
- strcpy(e->Prezime,s->Elements[s->Vrh].Prezime);
- e->b1=s->Elements[s->Vrh].b1;
- e->b2=s->Elements[s->Vrh].b2;
- return 1;
- }
- void StogNew(SP *s)
- {
- s->Vrh=-1;
- int pos;
- for(pos=0;pos<100;pos++){
- strcpy(s->Elements[pos].Ime,"nemaIMe");
- strcpy(s->Elements[pos].Prezime,"nemaPrezime");
- s->Elements[pos].b1=0;
- s->Elements[pos].b2=0;
- }
- }
- */
Add Comment
Please, Sign In to add comment