Professional Documents
Culture Documents
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int Linear(int A[10],int n,int ele)
{
for(int i=0;i<n;i++)
{
if(A[i]==ele)
return i+1;
}
return -1;
}
int small,pos,i,j=0;
cout<<"\n\n\t\t\tElements before Exchange Selection sorting:";
for(i=0;i<n;i++)
cout<<A[i]<<" ";
for(i=0;i<n-1;i++)
{
small=A[i];
for(j=i+1;j<n;j++)
{
if(A[j]<small)
{
small=A[j];
pos=j;
}
}
int temp=A[i];
A[i]=A[pos];
A[pos]=temp;
}
cout<<"\n\n\t\t\tElements after Exchange Selection sorting:";
for(i=0;i<n;i++)
cout<<A[i]<<" ";
}
void main()
{
cout<<"\t\t\t\Welcome to C++ ";
int A[100],n,i,choice,ele,X;
cout<<"\n\nEnter size of integer array:";
cin>>n;
cout<<"\n\nEnter elements in integer array:";
for(i=0;i<n;i++)
cin>>A[i];
cout<<"\n\t\t\tSelect operation to be performed:-\n\n1.Linear
Search\n\n2.Binary Search\n\n3.Bubble Sorting\n\n4.Exchange
Selection Sorting\n\n5.Insertion of element into array\n\n6.Delete an
element from array\n\nEnter your choice:";
cin>>choice;
switch(choice)
{
case 1:cout<<"\n\n\t\t\tLinear Search";
cout<<"\n\nEnter element to be searched:";
cin>>ele;
if(Linear(A,n,ele)==-1)
cout<<"\n\nElement not found";
else
cout<<"\n\nElement found at:"<<Linear(A,n,ele);
break;
case 2:cout<<"\n\n\t\t\tBinary Search";
cout<<"\n\nEnter element to be searched:";
cin>>ele;
if(Binary(A,n,ele)==-1)
cout<<"\n\nElement not found";
else
cout<<"\n\nElement found at:"<<Binary(A,n,ele);
break;
case 3:Bubble(A,n);
break;
case 4:Selection(A,n);
break;
case 5:cout<<"\n\n\t\t\tInsert Element into Array:";
cout<<"\n\nEnter element to be inserted:";
cin>>ele;
X=findpos(A,n,ele);
cout<<"\n\nElement inserted at:"<<X;
Insert(A,&n,X,ele);
break;
case 6:cout<<"\n\n\t\t\tDelete Element into Array:";
cout<<"\n\nEnter element to be deleted:";
cin>>ele;
X=findpos(A,n,ele);
Del(A,&n,X);
break;
default:cout<<"\nInvalid choice:";
}
}