0% found this document useful (0 votes)
3 views1 page

Stack Using Linked List PGM

The document contains a C program that implements a stack data structure using a linked list. It includes functions for pushing, popping, and displaying stack elements, along with a main menu for user interaction. The code demonstrates basic stack operations and error handling for invalid inputs.

Uploaded by

aasiyahafis2
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)
3 views1 page

Stack Using Linked List PGM

The document contains a C program that implements a stack data structure using a linked list. It includes functions for pushing, popping, and displaying stack elements, along with a main menu for user interaction. The code demonstrates basic stack operations and error handling for invalid inputs.

Uploaded by

aasiyahafis2
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/ 1

S3 CS STACK USING LS CEK

#include <stdio.h> {
#include <stdlib.h> struct node *newnode = (struct node *)malloc(sizeof(struct
node));
struct node
newnode->data = val;
{
if (top == NULL)
int data;
newnode->next = NULL;
struct node *next;
else
} *top = NULL;
newnode->next = top;
void push(int);
top = newnode;
void pop();
}
void display();
void pop()
void main()
{
{
if (top == NULL)
int ch, val;
printf("Empty Stack");
printf("Stack Using Linked List");
else
for (;;)
{
{
struct node *temp = top;
printf("\n1.Push\t2.Pop\t3.Display\t4.Exit\tChoice: ");
top = top->next;
scanf("%d", &ch);
free(temp);
switch (ch)
}
{
}
case 1:
void display()
printf("Enter value: ");
{
scanf("%d", &val);
if (top == NULL)
push(val);
printf("Empty Stack");
break;
else
case 2:
{
pop();
struct node *temp = top;
break;
printf("Stack from top: ");
case 3:
while (temp->next != NULL)
display();
{
break;
printf("%d<---", temp->data);
case 4:
temp = temp->next;
return;
}
default:
printf("%d<---NULL", temp->data);
printf("Invalid Input");
}
}}}
}
void push(int val)

You might also like