Vous êtes sur la page 1sur 4

Menu Driven program of

Insertion,Deletion and Binary Search


#include<iostream.h>
#include<conio.h>
void main(
!
clrscr("
int #,p,a$%&',n,d,t(&,ch"
char l"
do
!
cout<<)*nter the length of array)"
cin>>n"
cout<<)*nter the elements)"
for(int i(&"i<n"i++
cin>>a$i'"
cout<<)Menu,n-.Insertion,n%.Deletion,n..Binary
Search)<<endl"
cout<<)*nter your choice )"
cin>>ch"
s/itch(ch
!
case -0
cout<<)*nter the position )"

cin>>p"
cout<<)*nter the element to 1e inserted )"
cin>>#"
if(p<(n+-
!
for(i(n"i>(p"i22
a$i'(a$i2-'"
a$p2-'(#"
n++"
cout<<)*lements after insertion are)<<endl"
for(i(&"i<n"i++
cout<<a$i'<<endl"
3
else
cout<<)4rong 5osition)"

1rea6"



case %0
cout<<)*nter the element to 1e deleted )"
cin>>d"
for(i(&"i<n"i++
!
if(a$i'((d
!
for(int 6(i"6<(n2-"6++
a$6'(a$6+-'"
t(-"
1rea6"
3
3
if(t((-
!
n22"
cout<<)7rray after deletion is)<<endl"
for(i(&"i<n"i++
cout<<a$i'<<endl"
3
else
cout<<)4rong *lement)"
1rea6"
case .0
int l,h,m,s"
l(&"
h(n2-"
cout<<)*nter the element to 1e searched )"
cin>>s"
/hile(l<(h
!
m((l+h8%"
if(a$m'((s
!
cout<<)*lement found at )<<m+-<<)
5osition)"
t(-"
1rea6"
3
else if(s>a$m'
l(m+-"
else
h(m2-"
3
if(t((&
cout<<)*lement not found)"
1rea6"
default0
cout<<)5lease *nter the given
choices)<<endl"
3
cout<<)Do you /ish to continue(y8n )"
cin>>l"
3/hile(l((9y9::l((9;9"
getch("
3

Vous aimerez peut-être aussi