# Stack using Linked List.

- Link: https://technotaught.com/stack-using-linked-list/
- Published: 2018-11-10T19:03:15+05:30
- Author: Ashishkumar Vishwakarma

This article explains to you how to implement Stack using Linked List. 

1. What is a Stack? 
ANS.: An Ordered collection of elements using LIFO(Last in 
First Out) mechanism.

2. Operations performed on the stack? 
ANS.: Push (insertion), pop (deletion), peek(
Topmost element) & display.

3. Applications of a stack? 
ANS.: Infix, Postfix, and Prefix notations, Recursive
functions, Function cell, Expression evaluation, etc.

### Graphical Representation.

![Stack using Linked List.](https://i1.wp.com/www.technotaught.com/wp-content/uploads/
2018/11/stack-1.jpg?zoom=1.5449999570846558&w=800&ssl=1)

Stack using Linked List.

 Also, you can use the C [compiler](https://www.onlinegdb.com/online_c_compiler)
to compile a program.

## Program for Stack using LL.

### Source code.

    ```wp-block-code
    #include<stdio.h>
    #include<stdlib.h>


    struct node
    {
    	int data;
    	struct node * addr;
    };
    struct node * start;
    void push(int);
    void pop();
    void disp();

    int main()
    {	
    	push(10);
    	push(20);
    	push(30);
    	push(40);
    	pop();
    	pop();
    	pop();
    	pop();

    }

    void push(int val)
    {
    	struct node * temp,*i=start,*top ;
    	temp=(struct node *) malloc (sizeof (struct node));
    	temp -> data=val;
    	temp-> addr=NULL;

    	if(start==NULL)
    	{
    		start=temp;
    	}
    	else


    		top->addr=temp;
    		top=temp;

    	disp();
    }

    void disp()
      {
      	struct node * i=start;

      		printf("\nstackd: ");
      		while(i!=NULL)
      		{
      			printf("%d ",i->data);
      			i=i->addr;
    		}

      }

     void pop()
    	{
    		struct node *i=start,*top;
    		if(start!=NULL)
    		{
    			while(i->addr!=top)
    			{
    				i=i->addr;
    			}
    			i->addr=NULL;
    			top=i;
    			if(start==NULL)
    			{
    				top=NULL;
    			}
    			disp();
    		}
    	}
    ```

### Output.

> stack_d: 10_
> stackd: 10 20stackd: 10 20 30stackd: 10 20 30 40stackd: 10 20 30stackd:
> 10 20stack_d: 10_

Also view – [Queue using a linked list](https://technotaught.com/stack-using-linkedlist/).

### Share this:

 * [  X ](https://technotaught.com/stack-using-linked-list/?share=twitter)
 * [  Facebook ](https://technotaught.com/stack-using-linked-list/?share=facebook)
 * [More](https://technotaught.com/stack-using-linked-list/#)

 * [  WhatsApp ](https://technotaught.com/stack-using-linked-list/?share=jetpack-whatsapp)
 * [  LinkedIn ](https://technotaught.com/stack-using-linked-list/?share=linkedin)
 * [  Email ](https://technotaught.com/stack-using-linked-list/?subject=%5BShared%20Post%5D%20Stack%20using%20Linked%20List.&body=https%3A%2F%2Ftechnotaught.com%2Fstack-using-linked-list%2F&share=email)
 * [  Reddit ](https://technotaught.com/stack-using-linked-list/?share=reddit)
 * [  Tumblr ](https://technotaught.com/stack-using-linked-list/?share=tumblr)
 * [  Pinterest ](https://technotaught.com/stack-using-linked-list/?share=pinterest)
 * [  Telegram ](https://technotaught.com/stack-using-linked-list/?share=telegram)
 * [  Print ](https://technotaught.com/stack-using-linked-list/#print?share=print)

### _Related_

## Comments

### By: Mindy B

- Link: https://technotaught.com/stack-using-linked-list/#comment-144
- Published: 2020-04-26T12:53:54+05:30

Thanks for posting this. Keep up the great effort.\|
