[ create a new paste ] login | about

Link: http://codepad.org/9TdyQuOz    [ raw code | output | fork ]

C, pasted on Oct 26:
#include<stdio.h>

struct stack1
{
    int a[10],top;
};
typedef struct stack1 stack;
initialize(stack *s)
{
    s->top=-1;
}
int push(stack *s,int x)
{
    return(s->top!=(10-1)?s->a[++s->top]=x,1:0);
}
int pop(stack *s)
{
    return(s->top==-1?-999:s->a[s->top--]);
}
main()
{
    stack s;
    initialize(&s);
    int d=5;//data
    for(;push(&s,d++););
    for(;1;)
    {
        int d=pop(&s);
        if(d==-999)
        break;
        printf("%d\n",d);

    }

}//http://programmingconsole.blogspot.com/


Output:
1
2
3
4
5
6
7
8
9
10
11
12
14
13
12
11
10
9
8
7
6
5

Exited: ExitFailure 25


Create a new paste based on this one


Comments: