Wednesday, September 28, 2022

Data Structures and Algorithms (Stack as Link List) - Tirthankar Pal - MBA from IIT Kharagpur, GATE, GMAT, IIT Written Test, Interview were a part of MBA Entrance, B.S. in Computer Science from NIELIT

Stack implemented by a Link 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;

   else

      newNode->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);

   }

}

void display()

{

   if(top == NULL)

      printf("\nStack is Empty!!!\n");

   else{

      struct Node *temp = top;

      while(temp->next != NULL){

                     printf("%d--->",temp->data);

                     temp = temp -> next;

      }

      printf("%d--->NULL",temp->data);

   }

}

Tirthankar Pal

MBA from IIT Kharagpur with GATE, GMAT, IIT Kharagpur Written Test, and Interview

2 year PGDM (E-Business) from Welingkar, Mumbai

4 years of Bachelor of Science (Hons) in Computer Science from the National Institute of Electronics and Information Technology

Google and Hubspot Certification

Brain Bench Certification in C++, VC++, Data Structure and Project Management

10 years of Experience in Software Development out of that 6 years 8 months in Wipro

Selected in Six World Class UK Universities:-

King's College London, Durham University, University of Exeter, University of Sheffield, University of Newcastle, University of Leeds




No comments:

Post a Comment