0% found this document useful (0 votes)
7 views4 pages

Abhay SLL2

The document contains a C program that implements a stack using a linked list. It includes functions for pushing, popping, and displaying elements in the stack, along with a menu-driven interface for user interaction. The program handles user choices for stack operations and manages memory allocation for the linked list nodes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Abhay SLL2

The document contains a C program that implements a stack using a linked list. It includes functions for pushing, popping, and displaying elements in the stack, along with a menu-driven interface for user interaction. The program handles user choices for stack operations and manages memory allocation for the linked list nodes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name-ABHAY R KULKARNI PRN-221041064 S.

E Comps 202324

#include<stdio.h>

#include<stdlib.h> struct

Node

int data; struct

Node *next; }*top

= NULL; void

push(int); void

pop(); void

display(); void

main()

int choice, value; clrscr(); printf("\n:: Stack

using Linked List ::\n"); while(1){ printf("\n***

MENU ***\n"); printf("1. Push\n2. Pop\n3.

Display\n4. Exit\n"); printf("Enter your choice:

"); scanf("%d",&choice); switch(choice){ case

1: printf("Enter the value to be insert: ");

scanf("%d", &value); push(value); break;

case 2: pop(); break; case 3: display(); break; case 4:

exit(0); default: printf("\nWrong selection!!! Please try

again!!!\n");

}
Name-ABHAY R KULKARNI PRN-221041064 S.E Comps 202324

void push(int value)

struct Node *newNode; newNode = (struct

Node*)malloc(sizeof(struct Node)); newNode->data =

value; if(top == NULL) newNode->next = NULL;

else

newNode->next = top; top =

newNode; printf("\nInsertion is

Success!!!\n");

void pop()

if(top == NULL)

printf("\nStack is Empty!!!\n");

else{ struct Node *temp =

top; printf("\nDeleted

element: %d", temp->data);

top = temp->next; free(temp);

void display()

{
Name-ABHAY R KULKARNI PRN-221041064 S.E Comps 202324

if(top == NULL)

printf("\nStack is Empty!!!\n");

else{ struct Node *temp =

top; while(temp->next !=

NULL){ printf("%d--->",temp-

>data); temp = temp -> next;

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

}
Name-ABHAY R KULKARNI PRN-221041064 S.E Comps 202324

You might also like