0% found this document useful (0 votes)
83 views9 pages

Data Structure Lab Manual 2022-23

The document is a data structure lab manual submitted by Sourabh Samaniya to Diksha Ruhela. It contains 5 programs: 1) array operations using functions, 2) sorted list operations, 3) singly linked list operations, 4) unsorted list operations, and 5) a menu-driven stack implementation using an array. The fifth program code implements push, pop, isEmpty, isFull, and view functions for a stack using an array with a main menu loop for testing.
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)
83 views9 pages

Data Structure Lab Manual 2022-23

The document is a data structure lab manual submitted by Sourabh Samaniya to Diksha Ruhela. It contains 5 programs: 1) array operations using functions, 2) sorted list operations, 3) singly linked list operations, 4) unsorted list operations, and 5) a menu-driven stack implementation using an array. The fifth program code implements push, pop, isEmpty, isFull, and view functions for a stack using an array with a main menu loop for testing.
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/ 9

DATA STRUCTURE LAB MANUAL

{ fifth semester 2022-23}

SUBMITTED BY:

SOURABH SAMANIYA
2K20/EP/104
ENGINEERING PHYSICS
DS-SECTION 2-GROUP 3

SUBMITTED TO :

Diksha Ruhela mam

DELHI TECHNOLOGICAL UNIVERSITY

(FORMERLY Delhi College of Engineering)


Bawana Road, Delhi-110042

1
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
VISION : The Department of Computer Science & Engineering strives to be a leading
world class technology department with excellence in creating, applying, and
imparting theoretical, experimental, and applied knowledge through comprehensive
educational programs and collaborative research, playing its role as a key node in
national and global network to empower the industry and society with the wings of
knowledge and power of innovation.

MISSION :

1. To nurture the talent of students for research, innovation and

excellence in the field of Computer Science & Engineering.

2. To develop highly analytical and qualified computer engineers

by giving hands-on training on cutting-edge technology.

3. To produce socially responsible computer engineers with

professional ethics.

4. To focus on R&D environment in close partnership with

industry and academia globally.

5. To produce up-to date, scientifically tempered, design oriented

engineers and scientists capable of lifelong learning.

2
CONTENT
PROGRAM 1: program that uses functions to perform the following operations on an array i)
Creation ii) Insertion iii) Deletion iv) Traversal.

PROGRAM 2: Managing sorted list:- menu driven program to perform insert, delete and search
operations.

PROGRAM 3: Write a program that uses functions to perform the following operations on singly
linked list i) Creation ii) Insertion iii) Deletion iv) Traversal.

PROGRAM 4: Write a program to manage unsorted list- menu driven program to perform insert,
Delete and search operations

PROGRAM 5: Write a program to Implement stack using array:- menu driven program.

3
PROGRAM : 5

Aim: Write a program to Implement stack using array:- menu driven program.

Software used -visual studio code .

Algorithm-
PUSH ALGORITHM
Step 1: Declare global variable ‘Top’ and Top--;
Step 2: if Top== size of array print “stack overflow”
Return
[end of if statement]
Step 3: print “data to be pushed”
Read i;
Step 4: ++Top;
Array[Top]=i

POP ALGORITHM
Step 1: Declare global variable ‘Top’ and Top--;
Step 2: if Top== -1 “stack underflow”
Return
[end of if statement]
Step 3: print “data to be pop”
Set i=array[Top]
Step 4: Top--;

4
Code-
//sourabh samaniya 2k20/ep/104
#include<stdio.h>
#include<iostream>

using namespace std;

class Stack
{
int top;
int arr[50];
public:
Stack()
{
top=-1;
}

void pushelement();
void popelement();
void viewstack();
int isEmpty();
int isFull();
};

int Stack::isEmpty()
{
return (top==(-1)?1:0);
}

int Stack::isFull()
{
return ( top == 50 ? 1 : 0 );
}

void Stack::pushelement()
{
if(isFull())
{
cout<<"\nSTACK IS FULL { OVERFLOW }";
}
else

5
{
int i;
cout<<"\nEnter an element :: ";
cin>>i;
++top;
arr[top]=i;
cout<<"\nInsertion successful.\n";
}
}

void Stack::popelement()
{
int num;
if(isEmpty())
{
cout<<"\n STACK IS EMPTY [ UNDERFLOW ] ";
}
else
{
cout<<"\nDeleted item is : "<<arr[top]<<"\n";
top--;
}
}

void Stack::viewstack()
{
if(isEmpty())
{
cout<<"\n STACK IS EMPTY [ UNDERFLOW ] ";
}
else
{
cout<<"\nSTACK :\n";
for(int i=top;i>=0;i--)
{
cout<<arr[i]<<"\n";
}
}
}

int main()

6
{
Stack s;
int choice;
choice=0;
while(choice!=4)
{
cout<<"\n1. Push the element\n";
cout<<"2. Pop thr element\n";
cout<<"3. Display stack\n";
cout<<"4. Quit\n";
cout<<"\nEnter your Choice :: ";
cin>>choice;

switch(choice)
{
case 1:
s.pushelement();
break;

case 2:
s.popelement();
break;

case 3:
s.viewstack();
break;

case 4:
choice=4;
cout<<"\nPress any key .. ";
break;

default:
cout<<"\nWrong Choice!! \n";
break;
}
}

return 0;
}

7
Result-

8
9

You might also like