You are on page 1of 5

Department of Electrical

Engineering
School of Science and Technology
Foundation University, Rawalpindi, Pakistan

Data Structure &Algorithm


Name:
Roll-no:
Lab 2: Array Data Structure part 2.
OBJECTIVES:

(i) Design a program using array data structure which has following features/
functions ?
 Print the entire array .
 Update a specific location in the array.
 Search for a particular element and return true or false.
 Search for a particular element for its location.
 Delete an element for a array.
 Insert a new element in an array.
(ii) Design a program which uses array data structure to change a repeated alphabets (any
particular alphabet user inserted) to another alphabet?

Performance Lab Report

Description Total Marks Description Total Marks


Marks Obtained Marks Obtained
Operate 5 5
Communication
Software
Code writing 5
Total Marks obtained
Remarks (if any): ………………………………….

Name & Signature of faculty: …………………………………

Input:

#include <iostream>

using namespace std;

void print(char *a,int l)

int i;

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

cout<<a[i]<<endl;

int find_2(char *a,int l,char ch)

int i;

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

if(a[i]==ch)

return i;

}
}

return -1;

void insert(char *a,int l,int y,char new_e)

int i;

for(i=l-1;i>y;i--)

a[i]=a[i-1];

a[y]=new_e;

void mydelete(char *a,int l,int b)

int i;

for(i=b;i<l-1;i++)

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

bool find_1(char *a,int l,char ch)

{
int i;

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

if(a[i]==ch)

return true;

return false;}

int main()

int a,b,c;

char arr[10];

for(a=0;a<10;a++)

cin>>arr[a];

char x;

cin>>x;

while(find_1(arr,10,x)==true)

{
b=find_2(arr,10,x);

mydelete(arr,10,b);

insert(arr,10,b,'k');

print(arr,10);

return 0;

Output:

You might also like