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)