[ create a new paste ] login | about

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

C, pasted on Sep 18:
#include <stdio.h>
#include <string.h>

struct stack_type{
       char *a[10];
       int rear;
       int front;
};
typedef struct stack_type stack;
void initialize(stack *s)
{

    s->front=-1;
    s->rear=-1;
}
int empty(stack *s)
{
    if(s->front==s->rear)return 1;
    return 0;
}
int full (stack *s)
{
    int i;
    if(s->rear==9)i=0;
    else{i=s->rear+1;}
    if(i==s->front)return 1;
    return 0;
}

/*int loc(int fr, int re)
{
    if((fr==-1) && (re==-1)){ re=1; fr=1; return fr ;}
    if(re>9)

}*/
void enqueue(stack *s,char x[])
{
    if(full(s))printf("full");
    else
    {
        if(s->rear==9)
        { s->rear=-1;}
        s->a[++(s->rear)]=x;
    }
}
char dequeue(stack *s)
{
    if(empty(s))printf("empty error");
    else
    {
        if(s->front==9)
        {s->front=0;}
        else{
            s->front++;

        }

    }
    return(s->a[s->front]);
}
main()
{
    stack mys;
    int i,x;
    initialize(&mys);
    enqueue(&mys,"namit");
    printf("%s \n",dequeue(&mys));

}


Output:
1
Segmentation fault


Create a new paste based on this one


Comments: