Advertisement
prakhar7999

test paste

Jan 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std ;
  3. void bubble(int a[],int n){
  4. for(int i=0;i<n;i++){
  5. for(int j=i;j<n;j++){
  6. if(a[i]>a[j]){
  7. int temp= a[i];
  8. a[i]=a[j];
  9. a[j]=temp;
  10. }
  11. }
  12. }
  13. }
  14. void bSearch(int a[],int n,int v){
  15. int f=0;
  16. int l=n-1;
  17. int m;
  18. while(f<=l){
  19. m=l+f/2;
  20. if(a[m]>v){
  21. l=m-1;
  22. }
  23. else if(a[m]<v){
  24. f=m+1;
  25. }
  26. else if(a[m]==v)
  27. break;
  28. }
  29. cout<<m;
  30. }
  31. int main(){
  32. int n,i,j;
  33. cin>>n;
  34. int a[n];
  35. for(i=0;i<n;i++){
  36. cin>>a[i];
  37. }
  38. bubble(a,n);
  39. for(i=0;i<n;i++){
  40. cout<<a[i];
  41. }
  42. cout<<"\n";
  43. bSearch(a,n,2);
  44.  
  45. return 0;
  46. }
  47.  
  48. !@#$%^*()!cpp!@#$%^*()!4
  49. 5
  50. 7
  51. 2
  52. 8
  53. 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement