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
Ramjac Company wants to set up k independent file servers, each capable of running the company's intranet. Each server has avera
Luda [366]

Answer:

k = 3

Explanation:

K independent file servers

Average "uptime" of each server = 98%

<u>To achieve 99.99% probability by the intranet </u>

given that each server has an uptime = 98%

For the intranet to achieve 99.99% probability we have to choose more than 2 servers ( i.e. 3 servers )  incase any of the server goes down.

As each server posses an uptime of 98% it is almost impossible for all 3 servers to go down at the same time hence value of K = 3

3 0
3 years ago
The database cannot be migrated to a different engine because sql server features are used in the application’s net code. The co
Nezavi [6.7K]

Answer:

Explanation:

B is correct

3 0
2 years ago
How does the speaker feel about traditional forms of poetry
Salsk061 [2.6K]
A speaker sometimes is not able to capture the intended details since it is affected by homophones.
7 0
4 years ago
Read 2 more answers
"The _____ of the Open Systems Interconnection (OSI) model generates the receiver’s address and ensures the integrity of message
aleksklad [387]

Answer:

The transport layer

Explanation: Layer 4, is the transport layer of the Open System Interconnection (OSI), that handles message transfer of data between end systems or hosts and ensures complete packets transfer.

7 0
3 years ago
Read 2 more answers
Your unit has an upcoming training event. What form is used to record and maintain document numbers for ammunition documents?
aleksklad [387]

Ammunition documents which caries bullet, fuses extra should be numbered properly.

<u>Explanation:</u>

A document number or page number should be well organized and he or she coordinates with assistant trainers who have involved it.

Since it is a training event. The trainer has to have a checklist and make as fill with page number and make sure page numbers are strictly followed during the training session. If any page number is misplaced through the training session it will be embracing the situation for trainer and student or staff who get the training.

8 0
3 years ago
Other questions:
  • Rachel is on her way to an interview for the position of a project manager. She is trying to prepare for this interview by analy
    6·1 answer
  • Look at the four schematic symbols shown in the figure above. Each of the symbols is labeled with a number. Which of the followi
    5·2 answers
  • What is a CPU made of
    13·2 answers
  • 2. What is an inanimate object? (1.0 points)
    14·1 answer
  • Which statements accurately describe the Bookmark feature in the Audio/Video control bar? Check all that apply.
    13·1 answer
  • Which programming language was released first
    7·1 answer
  • What is Naptha used for?
    9·2 answers
  • Which model represents any process in general?
    6·1 answer
  • I really need help in this!!!
    11·1 answer
  • What dictionary operation can you use to remove all the keys within the dictionary-named contacts?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!