请搭配选择/冒泡排序使用o

#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int a[10],key=0,mid;
  cin>>key;
  for(int i=0;i<10;i++){
    cin>>a[i];
  }
  int left=0,right=9;
  while(left<=right){
    mid=(left+right)/2;
    if(a[mid]==key){
      cout<<mid+1;
      break;
    }else if(key<a[mid]){
      right=mid-1;
    }else{
      left=mid+1;
    }
  }
  if(left>right){
    cout<<-1;
  }
  return 0;
}

选择排序

#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int max;
    int a[10]={1,3,2,8,4,5,7,11,9,10};
    for(int i=0;i<10;i++){
        max=i;
        for(int j=i;j<10;j++){
            if(a[j]>a[max])
                max=j;
        }
        swap(a[i],a[max]);
    }
    for(int i=0;i<10;i++)
        cout<<a[i]<<' ';
    return 0;
}