Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Program bubble sort:#include<iostream.h> #include<conio.h> void main() { int a[100],n,i,temp; clrscr(); cout<<"enter no.

of elements:"; cin>>n; cout<<"enter elements:"; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter an element which you want to insert in a array:"; cin>>item; cout<<"enterthe location where you want to insert an element in a array:"; cin>>loc; for(i=loc;i>=loc;i--) a[i+1]=a[i]; a[loc]=item; n=n+1; cout<<"no. of element:<<n; cout<<"list after inserting an element is:"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"\t"; getch(); }

Insertion program:#include<iostream.h> #include<conio.h> void main() { int a[100],n,i,loc,item; clrscr(); cout<<"enter no. of elements:"; cin>>n; cout<<"enter elements:"; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter an element which you want to insert in a array:"; cin>>item; cout<<"enterthe location where you want to insert an element in a array:"; cin>>loc; for(i=n;i>=loc;i--) a[i+1]=a[i]; a[loc]=item; n=n+1; cout<<"no. of element:"<<n; cout<<"list after inserting an element is:"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"\t"; }

/*delete an element in array*/ #include<iostream.h> #include<conio.h> void main() { int a[100],item,n,i,loc; clrscr(); cout<<"enter no. of elements:"; cin>>n; cout<<"enter elements:"; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter the location from where you want to delete an element:"; cin>>loc; item=a[loc]; for(i=loc;i<n;i++) a[i]=a[i+1]; n=n-1; cout<<"no. of elements:"<<n<<endl; cout<<"elements are:"<<endl; for(i=0;i<n;i++) cout<<a[i]<<"\t"; getch(); }

You might also like