Implementation of Stack using Linked List

Added on - 20 Sep 2019

  • 3

    Pages

  • 427

    Words

  • 183

    Views

  • 0

    Downloads

Trusted by +2 million users,
1000+ happy students everyday
Showing pages 1 to 1 of 3 pages
IMPLEMENTATION OF STACK USING LNKED LIST#include<stdio.h>#include<conio.h>struct Node{int data;struct Node *next;}*top = NULL;void push(int);void pop();void display();void main(){int choice, value;clrscr();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 be insert: ");scanf("%d", &value);push(value);break;case 2: pop(); break;case 3: display(); break;case 4: exit(0);default: printf("\nWrong selection!!! Please try again!!!\n");}}}void push(int value){struct Node *newNode;newNode = (struct Node*)malloc(sizeof(struct Node));newNode->data = value;if(top == NULL)newNode->next = NULL;elsenewNode->next = top;top = newNode;printf("\nInsertion is Success!!!\n");}void pop(){if(top == NULL)printf("\nStack is Empty!!!\n");else{struct Node *temp = top;printf("\nDeleted element: %d", temp->data);top = temp->next;free(temp);
desklib-logo
You’re reading a preview
Preview Documents

To View Complete Document

Click the button to download
Subscribe to our plans

Download This Document