0% found this document useful (0 votes)
0 views

Stack n Queue Using Sll

Uploaded by

reemadnayak06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Stack n Queue Using Sll

Uploaded by

reemadnayak06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PUNE INSTITUTE OF COMPUTER TECHNOLOGY

PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

Title: Stack and queue using linked list

Problem Write a program in C to perform stack and queue using linked list. Verify its operations by
Statement following their principle of operation as LIFO, FIFO.

Programmer Name: Reema Nayak


Batch: G7

//STACK

#include<stdio.h>
struct stack
{
int data;
struct stack *next;
};
typedef struct stack stk;
stk *top=NULL;
void push(int value)
{
stk *temp;
temp=(stk *)malloc(sizeof(stk));
temp->next=NULL;
temp->data=value;
if(top==NULL)
{
top=temp;
}
else
{
temp->next=top;
top=temp;
}
printf("\nElement pushed is %d",value);
}

DS_LAB_2023-24: Program input output 1


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

void pop()
{
stk *temp;
if(top==NULL)
{
printf("\nStack underflow");
}
else
{
temp=top;
printf("\nPopped element is %d",top->data);
top=top->next;
free(temp);
}
}

void display()
{
if(top==NULL)
{
printf("\nStack underflow");
}
else
{
stk *trav;
printf("\nStack is:");
for(trav=top;trav!=NULL;trav=trav->next)
{
printf("\n%d",trav->data);
}
}
}

void main()

DS_LAB_2023-24: Program input output 2


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

{
int c,value;
while(1)
{
printf("\n\nEnter option:\n1.Push\n2.Pop\n3.Display\n4.Exit\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\nEnter value to be pushed: ");
scanf("%d",&value);
push(value);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(0);
}
}
}

------------------------------------------------------------------------------------------------------------------------------------------

//OUTPUT

Enter option:

DS_LAB_2023-24: Program input output 3


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

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

Enter value to be pushed: 4

Element pushed is 4

Enter option:
1.Push
2.Pop
3.Display
4.Exit
1

Enter value to be pushed: 5

Element pushed is 5

Enter option:
1.Push
2.Pop
3.Display
4.Exit
1

Enter value to be pushed: 6

Element pushed is 6

Enter option:
1.Push
2.Pop

DS_LAB_2023-24: Program input output 4


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

3.Display
4.Exit
3

Stack is:
6
5
4

Enter option:
1.Push
2.Pop
3.Display
4.Exit
2

Popped element is 6

Enter option:
1.Push
2.Pop
3.Display
4.Exit
2

Popped element is 5

Enter option:
1.Push
2.Pop
3.Display
4.Exit
3

Stack is:
4

DS_LAB_2023-24: Program input output 5


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

Enter option:
1.Push
2.Pop
3.Display
4.Exit
4

------------------------------------------------------------------------------------------------------------------------------------------

//QUEUE

#include<stdio.h>
struct queue
{
int data;
struct queue *next;
};
typedef struct queue Q;
Q *front=NULL;
Q *rear=NULL;

void insert(value)
{
Q *temp;
temp=(Q *)malloc(sizeof(Q));
temp->next=NULL;
temp->data=value;
printf("\nInserted value is %d",value);
if(front==NULL)
{
front=temp;
}
else
{
rear->next=temp;
}

DS_LAB_2023-24: Program input output 6


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

rear=temp;
}

void del()
{
if(front==NULL)
{
printf("\nQueue is empty");
}
else
{
Q *temp;
temp=front;
printf("\nRemoved elment is: %d",front->data);
front=front->next;
if(front==NULL)
{
rear=NULL;
}
free(temp);
}
}

void display()
{
if(front==NULL)
{
printf("\nQueue is empty");
}
else
{
Q *trav;
trav=front;
printf("\nQueue is: ");
while(trav!=NULL)
{

DS_LAB_2023-24: Program input output 7


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

printf("%d ",trav->data);
trav=trav->next;
}
}
}

void main()
{
int c,value;
while(1)
{
printf("\n\n1.Insert\n2.Delete\n3.Display\n4.Exit\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("\nEnter value to be added: ");
scanf("%d",&value);
insert(value);
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
exit(0);
}
}
}

//OUTPUT

1.Insert

DS_LAB_2023-24: Program input output 8


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

2.Delete
3.Display
4.Exit
1

Enter value to be added: 1

Inserted value is 1

1.Insert
2.Delete
3.Display
4.Exit
1

Enter value to be added: 2

Inserted value is 2

1.Insert
2.Delete
3.Display
4.Exit
1

Enter value to be added: 3

Inserted value is 3

1.Insert
2.Delete
3.Display
4.Exit
3

Queue is: 1 2 3

DS_LAB_2023-24: Program input output 9


PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication
ASSESMENT YEAR: 2023-2024 CLASS: SE
SUBJECT: DATA STRUCTURES
EXPT No: LAB Ref: SE/2023-24/ Starting date:
Roll No: 22351 Submission date:

1.Insert
2.Delete
3.Display
4.Exit
2

Removed elment is: 1

1.Insert
2.Delete
3.Display
4.Exit
2

Removed elment is: 2

1.Insert
2.Delete
3.Display
4.Exit
3

Queue is: 3

1.Insert
2.Delete
3.Display
4.Exit
4

DS_LAB_2023-24: Program input output 10

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy