Jumat, 08 Januari 2010

stack

#include
#include

typedef struct
{ int wadah [5];
int Top; }Stack;
typedef enum
{ false,
true }boolean;
void CreateStack(Stack *S);
boolean IsFullStack(Stack S);
boolean IsEmptyStack(Stack S);
void push(Stack *S, char E);
void pop(Stack *S, char *E);

main()
{ /*kamus*/
Stack A; char x;

/*ALGORITMA*/
clrscr();
CreateStack(&A);
push(&A,'D');
push(&A,'C');
pop(&A,&x);
printf("%c",x);

getch();

}


/*BODY PROTOTIPE*/
void CreateStack(Stack *S)
{/**/
int i;
/**/
Top(*S)==0;
for(i=1;i<=5;i++)
{(*S).wadah[i]=0;}
}

boolean IsFullStack(Stack S)
{ if(Top(S)==5)
{return true;}
else
{return false;}
}

boolean IsEmptyStack(Stack S)
{return Top(S)==0;}

void push(Stack *S, char E)
{ if(!IsFullStack(*S))
{Top(*S)==Top(*S)+1;}

(*S).wadah[Top(*S)]=E;
}

void pop(Stack *S, char *E)
{ if(!IsEmptyStack(*S))
{E=(*S).wadah[Top(*S)];}

(*S).wadah[Top(*S)]=0;
Top(*S)==Top(*S)-1;
}

Tidak ada komentar:

Posting Komentar