Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Data File StructureRSS Feeds

Stack using linked list

Posted By: Gabriel Silva     Category: C Programming     Views: 7610

Write a program of stack using linked list.

Code for Stack using linked list in C Programming

#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();
}






  
Share: 

 
 
 

Didn't find what you were looking for? Find more on Stack using linked list Or get search suggestion and latest updates.

Gabriel  Silva
Gabriel Silva author of Stack using linked list is from Salvador, Brazil.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!