STACK USING LINKED LIST

476

 

 

 

 

bca third semester stack using linked list program data structure

 

 

 

#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct stack
{
 int data;
 struct stack *next;
};struct stack *nw, *temp, *top;

void push()
{
 int item;
 clrscr();
  printf("Enter Element : ");
  scanf("%d",&item);
   if(top->data == NULL)
     top->data = item;
    else
     {
      nw = (struct stack *)malloc(sizeof(struct stack));
      nw -> data = item;
      nw -> next = top;
      top = nw;
     }
}



void pop()
{
 clrscr();
 if(top->data == NULL)
   printf("\nSTACK UNDERFLOW ! ! !");
  else
   {
    temp = top;
    top = top -> next;
     printf("%d is element deleted . . .",temp->data);
     free(temp);
   }
 }

void display()
{
  if(top->data == NULL)
    printf("STACK UNDERFLOW . . .");
   else
    {
     temp = top;
      while(temp != NULL)
       {
 printf("Your Stack Element : %d\n",temp->data);
 temp = temp->next;
 }
     }
 }



void main()
{
int ch;
 nw = (struct stack *)malloc(sizeof(struct stack));
 nw -> data = NULL;
 nw -> next = NULL;
 top = nw;
do
 {
clrscr();
 printf("1. Push Operation\n2. Pop Operation\n3. Display\n4. Exit\nEnter Any number : ");
 scanf("%d",&ch);
  switch(ch)
   {
    case 1:
      push();
     break;
    case 2:
      pop();
      getch();
     break;

    case 3:
      clrscr();
      display();
      getch();
     break;
    }
  }while(ch != 4);
 }

 

 

 

OUTPUT1. Push Operation
2. Pop Operation
3. Display
4. Exit
Enter Your Choice : 1
Enter any Number : 10
1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 1
Enter any Number : 20

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 1
Enter any Number : 30

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 1
Enter any Number : 40

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 1
Enter any Number : 50

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 3
Stack Element -
50
40
30
20
10

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 2
Deletion Element is = 50

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 2
Deletion Element is = 40

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 2
Deletion Element is = 30
1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 2
Deletion Element is = 20
1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 2
Deletion Element is = 10

1. Push Operation
2. Pop Operation
3. Display
4. Exit

Enter Your Choice : 2
STACK UNDERFLOW !!!!!!!!!

 

 

bca third semester stack using linked list program data structure 3rd sem

 

if you need a Downloadable link once message us on-page you can get at a time.

m.me/bcanotesnepal

This post is posted for not further third-party purposes.

Copyright By:-  Bcanotesneapl

Not allowed to upload these notes to other sites.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

if you want to download this PDF comment on us we will provide you a downloadable link.

if you like please share this post with your friend who studies in BCA

if you have any query please comment below,

if you like our sites. you can visit again for the latest updates notes of different BCA subjects of Presentation and different topics with assignment questions and solutions.

Don’t forget to like our page and post also share with your friend and having your group.

if you have any questions you can drop or share them with me using the comment box I will try to answer your question.

Like our Facebook Page https://www.facebook.com/bcanotesnepal/

LEAVE A REPLY

Please enter your comment!
Please enter your name here