Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std ;
- void bubble(int a[],int n){
- for(int i=0;i<n;i++){
- for(int j=i;j<n;j++){
- if(a[i]>a[j]){
- int temp= a[i];
- a[i]=a[j];
- a[j]=temp;
- }
- }
- }
- }
- void bSearch(int a[],int n,int v){
- int f=0;
- int l=n-1;
- int m;
- while(f<=l){
- m=l+f/2;
- if(a[m]>v){
- l=m-1;
- }
- else if(a[m]<v){
- f=m+1;
- }
- else if(a[m]==v)
- break;
- }
- cout<<m;
- }
- int main(){
- int n,i,j;
- cin>>n;
- int a[n];
- for(i=0;i<n;i++){
- cin>>a[i];
- }
- bubble(a,n);
- for(i=0;i<n;i++){
- cout<<a[i];
- }
- cout<<"\n";
- bSearch(a,n,2);
- return 0;
- }
- !@#$%^*()!cpp!@#$%^*()!4
- 5
- 7
- 2
- 8
- 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement