1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ket [755]
3 years ago
14

Write a c++ program which has array in fifteen element sort the array by selection the search for in element using binary search

Computers and Technology
1 answer:
sweet-ann [11.9K]3 years ago
6 0

Answer:

Explanation:

The following code is written in C++ and automatically implements the 15 element array. Then sorts it using selection sort. And finally implements a function that takes an element as a parameter and searches/returns that element using binary search.

#include<iostream>

using namespace std;

       int binarySearch(int arr[], int p, int r, int num) {

       if (p <= r) {

       int mid = (p + r)/2;

       if (arr[mid] == num)

       return mid ;

       if (arr[mid] > num)

       return binarySearch(arr, p, mid-1, num);

       if (arr[mid] > num)

       return binarySearch(arr, mid+1, r, num);

       }

       return -1;

       }

       int main() {

           int array[15] = {10, 20, 30, 31, 35, 15, 5, 9, 17, 22, 51, 55, 96, 42, 63};

           int size = 15;

           int i, j, imin;

           for(i = 0; i<size-1; i++) {

               imin = i;

           for(j = i+1; j<size; j++)

               if(array[j] < array[imin])

               imin = j;

               swap(array[i], array[imin]);

           }

           

       int chosenNumber = 31; //Any number that you want to search for

       int numberIndex = binarySearch (array, 0, n-1, num);

       }

You might be interested in
Write a MATLAB script using the quiver and contour commands to visualize the field and its divergence. Assume the region of inte
DochEvi [55]

Answer:

2b2t

Explanation:

2b2t

4 0
3 years ago
What is the primary responsibility of the physical layer in data communication?
melamori03 [73]
 It is responsible for transmitting these bits as signals over a wire, optical fiber, wireless, or other <span>medium.</span>
3 0
3 years ago
Hey guys im just curious.... whats ur favorite number
Oksana_A [137]

Answer:

13

Explanation:

8 0
3 years ago
Read 2 more answers
What type of tests is suitable for automated testing?
Shtirlitz [24]
Layering test
input-output test
UI regression test
unit test
integration test
code analysis
production logging and monitoring

8 0
3 years ago
What is the datapath of add instruction?
alina1380 [7]

i dont have enough information to awnser this

6 0
3 years ago
Other questions:
  • Need answer quick
    9·1 answer
  • You are given two int variables j and k, an int array zipcodelist that has been declared and initialized, and an boolean variabl
    7·1 answer
  • Which statement is true about the elements of the interface of a presentation program? The status bar appears at the top of the
    14·2 answers
  • He primary purpose for attackers to send port scanning probes to hosts is to identify which ports are open. true false
    5·1 answer
  • Individuals with desirable traits will be __________ to have young that survive than individuals without these traits. (2 points
    5·2 answers
  • True or false? any webb app can be accessed and run on any computing
    12·1 answer
  • An example of a ______ in the United States are computer hackers, whose members engage in actions that subvert authority, disrup
    6·1 answer
  • Kkkkkkkkkkkkkkkkkk kkkkkkkkkkkkkkkkkkkkkkkkkk
    15·2 answers
  • Tax preparation software can help prepare and file your taxes by _________.
    7·1 answer
  • The formula for calculating the amount of interest charged on a loan is:
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!