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
Advantages of a personal area network
Ratling [72]
The main advantage is the security, the pan is a personal network of one or two person so there is no risk of any leak of data, best way to share resources each other via bluetooth

4 0
4 years ago
Are self driving cars essential for the future of transportation
azamat
Yes, I think so at least because what about those who can't physically drive? They would want the experience of being in the driver's seat.
6 0
3 years ago
TWO QUICK QUESTIONS
andrezito [222]
I'm guessing 8? But I'm not 100% positive 
5 0
3 years ago
The protocol that enables computers on the Internet to communicate with one another is called ___
iren2701 [21]

Answer: TCP/IP

Explanation:

8 0
4 years ago
Read 2 more answers
Suppose you are an ad-serving company and you maintain a log of cookie data for ads you serve to the Web pages for a particular
Firlakuza [10]

Answer:

A

Explanation:

thethe more you have attached the more people are going to know your product so that it's going to be a long process which people can introduce to their friends

3 0
3 years ago
Other questions:
  • The "fathers of the Internet" are Vinton Cerf and ________. Select one: A. Robert Kahn B. Robert Cailliau C. Tim Berners-Lee D.
    11·1 answer
  • Write a program that reads a list of scores and then assigns grades python
    9·1 answer
  • Suppose we eliminate tcp and instead rely exclusively on udp as our only transport layer protocol. ⢠how does this impact opera
    15·1 answer
  • Write a program that reads a person's first and last names, separated by a space. Then the program outputs last name, comma, fir
    9·1 answer
  • What constructs break or bend the normal Syntax patterns of scheme?
    15·1 answer
  • With a heat exchanger, the temperature of the process fluid can be measured with a temperature-
    14·1 answer
  • 24 POINTS!!! <br> Why are Sequences, Selection, and Iteration building blocks of algorithms?
    5·1 answer
  • Is wireless or wired network faster??
    8·2 answers
  • Hello everyone. New ppl on Ro.blox? I want to play sometime.
    8·2 answers
  • You want to connect to a user desktop to review windows 10 configuration settings when the user is not present. which technology
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!