Professional Documents
Culture Documents
Stacksusinglinkedlist
Stacksusinglinkedlist
Stacksusinglinkedlist
h>
#include <stdlib.h>
struct node {
int info;
}*top,*top1,*temp;
int count = 0;
if (top == NULL)
top->ptr = NULL;
top->info = data;
else
temp->ptr = top;
temp->info = data;
top = temp;
}
count++;
printf("Node is Inserted\n\n");
int pop() {
top1 = top;
if (top1 == NULL)
printf("\nStack Underflow\n");
return -1;
else
top1 = top1->ptr;
free(top);
top = top1;
count--;
return popped;
void display() {
top1 = top;
if (top1 == NULL)
printf("\nStack Underflow\n");
return;
printf("%d--->", top1->info);
top1 = top1->ptr;
printf("NULL\n\n");
int main() {
while (1) {
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\nEnter the value to insert: ");
scanf("%d", &value);
push(value);
break;
case 2:
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\nWrong Choice\n");