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

Stack Linked List

The document provides a C programming implementation of a stack using a linked list. It includes functions for pushing, popping, and displaying stack elements, along with a menu-driven interface for user interaction. The code handles memory allocation and checks for stack underflow conditions.

Uploaded by

rajveerojha71
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)
12 views4 pages

Stack Linked List

The document provides a C programming implementation of a stack using a linked list. It includes functions for pushing, popping, and displaying stack elements, along with a menu-driven interface for user interaction. The code handles memory allocation and checks for stack underflow conditions.

Uploaded by

rajveerojha71
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

Implementation of Stack using Linked List | C Programming.

#include <stdio.h>

#include <stdlib.h>

struct Node {

int data;

struct Node *next;

} *top = NULL;

void push(int);

void pop();

void display();

int main() {

int choice, value;

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 insert: ");


scanf("%d", &value);

push(value);

break;

case 2:

pop();

break;

case 3:

display();

break;

exit(0);

default:

printf("\nWrong selection! Please try again.\n");

return 0;

void push(int value) {

struct Node *newNode;

newNode = (struct Node*)malloc(sizeof(struct Node));

if (newNode == NULL) {

printf("\nMemory allocation failed!\n");

return;

newNode->data = value;
newNode->next = top;

top = newNode;

printf("\nInsertion is successful!\n");

void pop() {

if (top == NULL)

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

else {

struct Node *temp = top;

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

top = temp->next;

free(temp);

void display() {

if (top == NULL)

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

else {

struct Node *temp = top;

printf("\nStack elements: ");

while (temp != NULL) {

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

temp = temp->next;
if (temp != NULL)

printf(" ---> ");

printf("\n");

You might also like