0% found this document useful (0 votes)
11 views8 pages

1 Stack

A student named Sayyed Sufiyan from class D6ADB implemented a stack using an array for their experiment. The objective was to implement basic data structures like arrays, linked lists, stacks and queues. The outcome was that students will be able to implement linear data structures and handle operations like insertion, deletion, searching and traversing on them. The student created functions for push, pop, peek and display and implemented a stack using an array with a maximum size of 5 that allows the user to select these options from a menu.

Uploaded by

Sufiyan Sayyed
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)
11 views8 pages

1 Stack

A student named Sayyed Sufiyan from class D6ADB implemented a stack using an array for their experiment. The objective was to implement basic data structures like arrays, linked lists, stacks and queues. The outcome was that students will be able to implement linear data structures and handle operations like insertion, deletion, searching and traversing on them. The student created functions for push, pop, peek and display and implemented a stack using an array with a maximum size of 5 that allows the user to select these options from a menu.

Uploaded by

Sufiyan Sayyed
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/ 8

Artificial Intelligence and Data Science Department

Subject/Odd Sem 2023-24/Experiment

Name : Sayyed Sufiyan Class/Roll No. Grade :


:D6ADB/65

Title of Experiment :Iplement Stack using Array

Objective of Experiment : To implement basic data structures such as arrays, linked lists,
stacks and queues

Outcome of Experiment :
• Students will be able to implement linear data structures & be able to handle
operations like insertion, deletion, searching and traversing on them.

Problem Statement :WAP to implement Stack Using Array


Artificial Intelligence and Data Science Department
Subject/Odd Sem 2023-24/Experiment
Description / Theory :
Artificial Intelligence and Data Science Department
Subject/Odd Sem 2023-24/Experiment
Artificial Intelligence and Data Science Department
Subject/Odd Sem 2023-24/Experiment
Artificial Intelligence and Data Science Department
Subject/Odd Sem 2023-24/Experiment
Artificial Intelligence and Data Science Department
Subject/Odd Sem 2023-24/Experiment

Program:
#include <stdio.h>
#define max 5
int stack[max];
int top = -1;
void push();
void pop();
void display();
void peek();

int main () {
int choice;
while(1)
{
printf ("***** MENU *****\n");
printf ("1. Push an element.\n");
printf ("2. Pop an element.\n");
printf ("3. Top element of the stack is:\n");
printf ("4. Display all the elements of stack.\n");
printf ("5. Quit.\n");
printf ("Enter your choice:");
scanf ("%d",&choice);
switch (choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peek();
break;
case 4:
display();
break;
case 5:
exit(0);
break;
default:
printf ("Invalid choice");
}
}

}
void push(){
if (top == max -1){
printf ("Stack is overflow,cannot push.\n");
Artificial Intelligence and Data Science Department
Subject/Odd Sem 2023-24/Experiment
} else{
int data;
top++;
printf ("Enter the data to be pushed:");
scanf ("%d",&stack [top]);
}

void pop(){
if (top == -1){
printf ("Stack is underflow, cannot pop.\n");
} else{
printf ("Element poped: %d\n",stack[top]);
top--;
}
}

void peek(){
if (top == -1){
printf ("Stack is underflow, cannot pop.\n");
} else{
printf ("Top element: %d\n",stack[top]);
}
}

void display(){
int i;
if (top == -1){
printf ("Stack is underflow, cannot pop.\n");
} else{
for (i=top; i>=0; i--){
printf ("%d \n",stack[i]);
}
}
}
Artificial Intelligence and Data Science Department
Subject/Odd Sem 2023-24/Experiment

Output Screenshot:

Results and Discussions :Implemented Successfully

You might also like