Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions C/stack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#define MAXSIZE 100
struct stacks{
int st[100];
int top;
};
typedef struct stacks stack;
void create(stack *s)
{
s->top=-1;
}
void push(stack *s,int e)
{
if(s->top==100-1)
{
printf("\n overflow");
exit(-1);
}
else{
s->top++;
s->st[s->top]=e;
}
}
int pop(stack *s)
{
if(s->top==-1)
{
printf("stack uunderflow\n");
exit(-1);
}
else{
return( s->st[s->top--]);
}

}
int isempty(stack *s)
{
if(s->top==-1)
return 1;
else
return 0;
}
int isfull(stack *s)
{
if(s->top==MAXSIZE-1);
}
int main()
{
stack A,B;
create(&A);create(&B);
push(&A,10);push(&B,20);
push(&A,30);
printf("%d %d\n",pop(&A),pop(&B));

}