Program No 1
Program No 1
Program No 1
int main() { int Arr[100],n,val,found; cout<<"Enter number of elements you want to insert "; cin>>n; for(int i=0;i<n;i++) { cout<<"Enter element "<<i+1<<":"; cin>>Arr[i]; }
found=lsearch(Arr,n,val);
getch(); return 0; }
int lsearch(int Arr[], int s, int VAL) { for(int I=0; I<s; I++) {
OUTPUT
PROGRAM NO 2
BINARY SEARCH #include<iostream.h> #include<conio.h>
int main() { int AR[100],n,val,found; cout<<"Enter number of elements you want to insert "; cin>>n; cout<<"Enter element in ascending order\n"; for(int i=0;i<n;i++) { cout<<"Enter element "<<i+1<<":"; cin>>AR[i]; }
found=bsearch(AR,n,val);
getch(); return 0; }
return 0; }
OUTPUT
main() { int array[15]; int no_el; clrscr(); cout<<"Enter the no of element :"; cin>>no_el; for(int i=0;i<no_el;i++) { cout<<"Enter the element : "; cin>>array[i]; }
while(1) { clrscr(); cout<<endl<<"1. Insert"; cout<<endl<<"2. delete by value"; cout<<endl<<"3. display"; cout<<endl<<"4. exit"; cout<<endl<<"Enter your choice : "; int choice; cin>>choice; switch(choice) { case 1: cout<<"Enter the position at which you want to insert : "; int pos; cin>>pos; cout<<"Enter the new element : "; cin>>new_el;
pos--; for(i=no_el-1;i>=pos;i--) array[i+1]=array[i]; array[pos]=new_el; no_el++; break; case 2: cout<<"Enter the value to be search : "; int key; cin>>key; for(pos=0;pos<no_el;pos++) { if(array[pos]==key) break; } if(pos==no_el) { cout<<"Search key not found";
break; } for(i=pos;i<no_el;i++) array[i]=array[i+1]; no_el--; break; case 3: cout<<endl; for(i=0;i<no_el;i++) cout<<endl<<"The element is : "<<array[i]; break; case 4: return(0); break; } getch(); } }
OUTPUT