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

Linkliststack PDF

This C program implements a stack using a linked list. It contains functions to push, pop, and view elements in the stack. The main function contains a while loop that displays a menu and uses switch statements to call the appropriate function based on the user's selection - push adds a new node to the head of the list, pop removes and deletes the first node, and view prints out the elements currently in the stack from head to tail.
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)
48 views1 page

Linkliststack PDF

This C program implements a stack using a linked list. It contains functions to push, pop, and view elements in the stack. The main function contains a while loop that displays a menu and uses switch statements to call the appropriate function based on the user's selection - push adds a new node to the head of the list, pop removes and deletes the first node, and view prints out the elements currently in the stack from head to tail.
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

#include <stdio.

h>
#include <conio.h>
#include <process.h>
struct node
{
int label;
struct node *next;
};
main()
{
int ch = 0;
int k;
struct node *h, *temp, *head;
/* Head node construction */
head = (struct node*) malloc(sizeof(struct node));
head->next = NULL;
while(1)
{
printf("\n Stack using Linked List \n");
printf("1->Push ");
printf("2->Pop ");
printf("3->View ");
printf("4->Exit \n");
printf("Enter your choice : ");
scanf("%d", &ch);
switch(ch)
{
case 1:
/* Create a new node */
temp=(struct node *)(malloc(sizeof(struct node)));
printf("Enter label for new node : ");
scanf("%d", &temp->label);
h = head;
temp->next = h->next;
h->next = temp;
break;
case 2:
/* Delink the first node */
h = head->next;
head->next = h->next;
printf("Node %s deleted\n", h->label);
free(h);
break;
case 3:
printf("\n HEAD -> ");
h = head;
/* Loop till last node */
while(h->next != NULL)
{
h = h->next;
printf("%d -> ",h->label);
}
printf("NULL \n");
break;
case 4:
exit(0);
}
}
}

You might also like