#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
int count=0;
typedef struct node{
int value;
struct stack *next;
struct stack *prev;
}stack;
stack *bottom=NULL;
stack *top=NULL;
stack *createnode(int a)
{
stack *newstack;
newstack
=(stack
*)calloc(1,sizeof(stack
)); newstack->value=a;
newstack->prev=NULL;
newstack->next=NULL;
return newstack;
}
int isempty()
{
if(count==0)
{return 1;}
else
{return 0;}
}
int isfull()
{
if(count==SIZE)
{return 1;}
else
{return 0;}
}
void push(int a)
{ if(isfull()==1)
{
printf("overflow condition: stack full"); }
else
{count+=1;
stack *newstack = createnode(a);
if(bottom==NULL)
{
bottom=newstack;
top=bottom;
}
else
{
top->next=newstack;
newstack->prev=top;
top=newstack;
}
}
}
int peek()
{
}
int pop()
{ if(isempty()==1)
{
printf("underflow condition:empty stack"); }
else
{if(count==1)
{ int c;
c=top->value;
top=NULL;
printf("popped value is:%d\n",c
); count=count-1;
}
else
{int c;
c=top->value;
top=top->prev;
top->next=NULL;
printf("popped value is:%d\n",c
); count=count-1;
}
}
}
int main(void) {
stack ruby; int i;
for(i=0;i<12;i++)
{push(i);
}
isfull();
pop();
pop();
pop();
pop();
pop();
pop();
pop();
pop();
pop();
pop();
pop();
int c=isempty();
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2RlZmluZSBTSVpFICAxMAppbnQgY291bnQ9MDsKdHlwZWRlZiBzdHJ1Y3Qgbm9kZXsKCWludCB2YWx1ZTsKCXN0cnVjdCBzdGFjayAqbmV4dDsKCXN0cnVjdCBzdGFjayAqcHJldjsKfXN0YWNrOwpzdGFjayAqYm90dG9tPU5VTEw7CnN0YWNrICp0b3A9TlVMTDsKc3RhY2sgKmNyZWF0ZW5vZGUoaW50IGEpCnsKCXN0YWNrICpuZXdzdGFjazsKCW5ld3N0YWNrPShzdGFjayopY2FsbG9jKDEsc2l6ZW9mKHN0YWNrKSk7CgluZXdzdGFjay0+dmFsdWU9YTsKCW5ld3N0YWNrLT5wcmV2PU5VTEw7CgluZXdzdGFjay0+bmV4dD1OVUxMOwoJcmV0dXJuIG5ld3N0YWNrOwp9CmludCBpc2VtcHR5KCkKICAgIHsKICAgICAgIGlmKGNvdW50PT0wKQogICAgICAge3JldHVybiAxO30KICAgICAgIGVsc2UKICAgICAgIHtyZXR1cm4gMDt9CiAgICB9CmludCBpc2Z1bGwoKQogICAgewogICAgCWlmKGNvdW50PT1TSVpFKQogICAgCXtyZXR1cm4gMTt9CiAgICAJZWxzZQogICAgCXtyZXR1cm4gMDt9CiAgICB9CnZvaWQgcHVzaChpbnQgYSkKeyAgIGlmKGlzZnVsbCgpPT0xKQogICB7CiAgIAlwcmludGYoIm92ZXJmbG93IGNvbmRpdGlvbjogc3RhY2sgZnVsbCIpOwogICB9CgllbHNlCiAgIHtjb3VudCs9MTsKCXN0YWNrICpuZXdzdGFjayA9IGNyZWF0ZW5vZGUoYSk7CglpZihib3R0b209PU5VTEwpCgl7IAoJYm90dG9tPW5ld3N0YWNrOwoJdG9wPWJvdHRvbTsKCX0KCWVsc2UKCXsKCQl0b3AtPm5leHQ9bmV3c3RhY2s7CgkJbmV3c3RhY2stPnByZXY9dG9wOwoJCXRvcD1uZXdzdGFjazsKCX0KICAgfQkKfQppbnQgcGVlaygpCiAgIHsKCSBwcmludGYoIiVkXG4iLHRvcC0+dmFsdWUpOwogICB9CmludCBwb3AoKQogICAgeyAgIGlmKGlzZW1wdHkoKT09MSkKICAgICAgICB7CiAgICAgICAgCXByaW50ZigidW5kZXJmbG93IGNvbmRpdGlvbjplbXB0eSBzdGFjayIpOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICB7aWYoY291bnQ9PTEpCiAgICAgICAgeyAgIGludCBjOwogICAgCSAgICBjPXRvcC0+dmFsdWU7CiAgICAgICAgCXRvcD1OVUxMOwogICAgICAgIAlwcmludGYoInBvcHBlZCB2YWx1ZSBpczolZFxuIixjKTsKICAgICAgICAJY291bnQ9Y291bnQtMT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