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
Convert the following decimal numbers into binary numbers. <br><br>pls ASAP<br>​
Anna007 [38]

Explanation:

Given, the cost price of the TV is Rs 24600. Now, the cooler costs Rs 800 more than one-third of the TV. The cost price of the cooler is Rs 9000.

6 0
3 years ago
To ensure rapid recovery and security of data, backup data should be ________.
Nataly [62]

Answer:B kept at a secure location at the facility

Explanation:

8 0
3 years ago
What are wizard ranks in brainly​
Hunter-Best [27]

Answer:

Brainly gives special ranks to users who give outstanding performance in a specific subject. These ranks are known as Wizard rank. Specifically for only one person in each subjects: Maths, Chemistry, Physics, Biology, and English.

Explanation:

4 0
3 years ago
Read 2 more answers
Ashley was asked by her principal to create a program for the commencement exercise held in June. How should she organize the in
natta225 [31]

Alphabetical Order. The answer(s) are on quizlet btw lol.

6 0
3 years ago
Were is the hype house
balandron [24]

Answer:

LA

Explanation:

where the rich people live

8 0
3 years ago
Read 2 more answers
Other questions:
  • What are career resources?
    7·2 answers
  • What device copies system files
    14·1 answer
  • Write a static method named evenNumbers that accepts a string of text as a parameter. Assume that the text is a series of intege
    5·2 answers
  • A ____ is a battery-operated power source directly attached to one or more devices and to a power supply (such as a wall outlet)
    14·1 answer
  • Which of the following statements is false? The ARPANET is the precursor to today’s Internet. Today’s fastest Internet speeds ar
    11·1 answer
  • 1.       An ________ works for a company to design, carry out, and solve its electronic equipment related problems.
    11·1 answer
  • Create a cell reference in a formula by typing in the cell name or
    7·2 answers
  • What laws are broken when you hack someone?
    9·1 answer
  • During the conflict resolution process, which of the followings statements would be appropriate when defining the problem?
    11·2 answers
  • What is the main purpose of dtp software?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!