0% found this document useful (0 votes)
28 views3 pages

11BEC1108 Stack Using Link List

This C code implements a stack using a linked list. It includes functions to push new nodes onto the stack, pop nodes off the stack, and display the contents of the stack. The main loop prompts the user for an operation choice and uses a switch statement to call the corresponding function until the user chooses to exit.

Uploaded by

Prakhar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views3 pages

11BEC1108 Stack Using Link List

This C code implements a stack using a linked list. It includes functions to push new nodes onto the stack, pop nodes off the stack, and display the contents of the stack. The main loop prompts the user for an operation choice and uses a switch statement to call the corresponding function until the user chooses to exit.

Uploaded by

Prakhar Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Stack using link list:

(11bec1108)

PRAKHAR SINGH

#include<stdio.h>

#include<stdlib.h>

#include<conio.h>

struct node

int data;

struct node *link;

};

struct node *top=NULL,*temp;

int main()

int choice,data;

while(1)

printf("\n1.Push\n2.Pop\n3.Display\n4.Exit\n");

printf("\nEnter ur choice:");

scanf("%d",&choice);

switch(choice)
{

case 1:

temp=(struct node *)malloc(sizeof(struct node));

printf("Enter a node data :");

scanf("%d",&data);

temp->data=data;

temp->link=top;

top=temp;

break;

case 2:

if(top!=NULL)

printf("The poped element is %d",top->data);

top=top->link;

else

printf("\nStack Underflow");

break;

case 3:

temp=top;

if(temp==NULL)

{
printf("\nStack is empty\n");

while(temp!=NULL)

printf("\n%d\n",temp->data);

temp=temp->link;

break;

case 4:

exit(0);

You might also like