Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment Title:-1

Student Name: Gulshan Kumar Singh UID: 21BCS2858


Branch: CSE Section/Group: 608-B
Semester: 3 Date of Performance: 26/08/2022
Subject Name: Data Structure Subject Code: 21CSH-211

1. Aim/Overview of the practical: Write a menu-driven program


that implements the following operations (using separate functions) on a
linear array:
1. Insert a new element at the end as well as at a given position.
2. Delete an element from a given whose value is given or whose position
is given.
3. To find the location of a given element.
4. To display the elements of the linear array.

2. Source Code:
#include<stdio.h>

#include<stdlib.h>

int a[100];

int n, i,value, position,toSearch,found;

void create();

void display();

void insert();

void delete();

void find_loc();

int main()

{
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

int choice=1;

while(choice)

printf("\n\n--------MENU-----------\n");

printf("1.CREATE\n");

printf("2.DISPLAY\n");

printf("3.INSERT\n");

printf("4.DELETE\n");

printf("5.FIND LOCATION\n");

printf("6.EXIT\n");

printf("-----------------------");

printf("\nENTER YOUR CHOICE:\t");

scanf("%d",&choice);

switch(choice)

case 1:

create();

break;

case 2:

display();

break;

case 3:

insert();

break;

case 4:

delete();

break;

case 5:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

find_loc();

case 6:

exit(0);

default:

printf("\nInvalid choice:\n");

break;

return 0;

void create()

printf("\nEnter the size of the array elements:\t");

scanf("%d",&n);

printf("\nEnter the elements for the array:\n");

for(i=0;i<n;i++)

scanf("%d",&a[i]);

void display()

int i;

printf("\nThe array elements are:\n");

for(i=0;i<n;i++)

printf("%d\t",a[i]);

}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

void insert()

printf("\nEnter the position for the new element:\t");

scanf("%d",&position);

printf("\nEnter the element to be inserted :\t");

scanf("%d",&value);

for(i=n-1;i>=position;i--)

a[i+1]=a[i];

a[position]=value;

n=n+1;

void delete()

printf("\nEnter the position of the element to be deleted:\t");

scanf("%d",&position);

value=a[position];

for(i=position;i<n-1;i++)

a[i]=a[i+1];

n=n-1;

printf("\nThe deleted element is =%d",value);

void find_loc()

{
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

printf("\nEnter element to search: ");

scanf("%d", &toSearch);

found = 0;

for(i=0; i<n; i++)

if(a[i] == toSearch)

found = 1;

break;

if(found == 1)

printf("\n%d is found at position %d", toSearch, i + 1);

else

printf("\n%d is not found in the array", toSearch);

}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

OUTPUT :

Evaluation Grid :
Sr. No. Parameters Marks Obtained Maximum Marks
1. Student Performance 12
(Conduct of experiment)
objectives/Outcomes.
2. Viva Voce 10
3. Submission of Work Sheet 8
(Record)
Total 30

You might also like