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
Can someone please help and answer the 6 questions on the bottom of the page
garik1379 [7]

Ivan rigney

John benson      2

Mark nicholls      4

James  mitchell   7

Paul matthews   13

Neil hooper         8

5 0
3 years ago
The class decided against learning new course material because they wanted to _____ the material that would be on their final ex
evablogger [386]

Answer:

ace, learn, memorize, comprehend

Explanation:

6 0
3 years ago
With a ____, the databases used by the system are all located on a single computer, such as a server or mainframe computer.
denpristay [2]

With a centralized database system, the databases used by the system are all located on a single computer, such as a server or mainframe computer.

<h3></h3><h3>What are database systems?</h3>

Database is a collection of related data stored in a manner that it can be retrieved as needed. Database system or Database Management System (DBMS) are enables us to create, maintain, and access databases. A database typically consists of Tables, Fields (columns) and Records (rows).

Advantages of DBMS approach are low level of redundancy, faster response time, lower storage requirements, easier to secure, increased data accuracy. Disadvantage of DBMS approach is increased vulnerability (backup is essential).

To learn more about database systems refer to:

brainly.com/question/518894

#SPJ4

5 0
2 years ago
What is a graphical representation of a real person in a virtual community called?
Hitman42 [59]
A graphical representation of a real person in a virtual community is an avatar.
8 0
4 years ago
Terrance is looking for a storage device to be used for backup storage. The device has to have a large storage capacity and be p
alexdok [17]

Answer:

externral hard drive

Explanation:

my friend told me

6 0
3 years ago
Read 2 more answers
Other questions:
  • Based on your understanding of Moore’s Law, what do you predict will be the next trend in the evolution of computers?
    10·1 answer
  • The two fundamental approaches to moving data through a network of links and switches are
    9·1 answer
  • What activities are coordinated by the OS?
    11·1 answer
  • What does it mean to say that a graph is complete?
    14·1 answer
  • PLZ ANSWER ALL MY QUESTION. Which line of code will display the variable num rounded to the nearest tenth?
    14·1 answer
  • Which of the following describes all illustrations created by freehand?
    15·1 answer
  • How to turn off microsoft teams message notifications
    13·1 answer
  • If you are going to build a custom fast PC for gaming and you need a lot of storage for big video files and videos, but you have
    11·1 answer
  • Your online actions can have real- world consequences. True or false?
    7·2 answers
  • To call the superclass's no-parameter constructor explicitly, use super(); group of answer choices true false
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!