C Programming Tutorial

 
 
 
 
#include<stdio.h>
#include<conio.h>

struct stack
{
    struct stack *back;
    int i;
};

void main()
{
    struct stack *top;
    struct stack *p;
    struct stack *end;
    int ch,user;
    clrscr();
    while(user!=5)
    {
        printf(\"\\n\\t 1. CREATE\");
        printf(\"\\n\\t 2. PUSH\");
        printf(\"\\n\\t 3. POP\");
        printf(\"\\n\\t 4. DISPLAY\");
        printf(\"\\n\\t 5. EXIT\");
        scanf(\"%d\",&user);
        if(user==1)
        {
            end=(struct stack*)malloc(sizeof(struct stack));
            end->back=0;
            printf(\"\\n\\t ENTER THE DATA IN STACK :::: \");
            scanf(\"%d\",&end->i);
            top=end;
        }
        if(user==2)
        {
            p=(struct stack*)malloc(sizeof(struct stack));
            p->back=top;
            printf(\"\\n\\t PUSH THE DATA IN STACK :::: \");
            scanf(\"%d\",&p->i);
            top=p;
        }
        if(user==4)
        {
            p=0;
            p=top;
            while(p!=0)
            {
                printf(\"\\n\\t %d-->\",p->i);
                p=p->back;
            }
        }
        if(user==3)
        {
            printf(\"\\n\\t DATA THAT IS POPPED IS ::: %d\",top->i);
            p=top->back;
            free(top);
            top=p;
        }
    }
    getch();
}

 
 
Didn't find what you were looking for? Find more on Stack using linked list