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
RUDIKE [14]
2 years ago
10

Write a C++ program that usesInsertion Sort to sort an unsorted list of numbers.

Computers and Technology
1 answer:
andrew11 [14]2 years ago
5 0

<u>C++ program - Insertion sort</u>

<u></u>

#include <bits/stdc++.h>  

using namespace std;  

/* Defining function for sorting numbers*/

void insertionSort(int array[], int n)  

{  

   int i, k, a;  

  for(i=1;i<n;i++)

           {

              k=array[i];

               a=i-1;

            while(a>=0 && array[a] > k) // moving elements of array[0 to i-1] are greater than k, to one position //

                      {

                       array[a+1] = array[a];

                        a =a-1;

                      }

              array[a+1] =k;

             }  

}              

/* Driver function */

int main()  

{  

   int array[] = { 12,56,76,43,21};   //input integers

   int n = sizeof(array) / sizeof(array[0]);   //finding size of array

 

   insertionSort(array, n);   //Calling function

    for (int i = 0; i < n; i++)   //printing sorted array

        cout << array[i] << " ";  

    cout << endl;  

    return 0;  

}  

You might be interested in
Assuming a 32bit processor If I have a double pointer defined as dPtr and I add 1 to it. How many bytes are added to the address
Anni [7]

Answer:

Theoretically one could design an architecture that would address 16 GB of memory with 32-bits of unique addresses.

Explanation:

4 0
2 years ago
The read/write heads of a hard disk gently rest on the hard disk platters in order to read and write the data.
noname [10]
The answer is FALSE because the interior of commercial Hard disk drive is with stack of magnetic disks (platters) containing the user’s data and a rotating arm supporting the magnetic heads. The rotating arm is moved by the torque generated by a voice coil motor (VCM) mounted at one end of the arm. Data read/write operations rely on the capability of the governing unit of the HDD to maintain the magnetic read/write heads as close as possible to center of the desired track. Typically, reliability of data reading and writing is guaranteed when the head is kept within 5% of the track pitch from the track center. This means that the accuracy required for the head positioning is in the range of a few tens of nanometers.
6 0
3 years ago
(b) The CPU is responsible for processing instructions.
Yakvenalex [24]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The CPU is responsible for processing instruction. CPU instruction processing goes through three stages. Fetch, Decode, and Execute.

When the program runs,  program code is copied from secondary storage into main memory. CPU's program counter set to the first instruction of the program stored in memory where the program starts executing.

When a program is being executed, it goes through fetch-decode-cycle. which repeats over and over again until reaching the STOP instruction.

The processor check which next instruction to be executed, then the processor fetches that instruction value from the memory location.  once the instruction being fetched it gets decoded and executed. This instruction processing cycle repeating until the CPU finds a stop instruction.

6 0
3 years ago
Read 2 more answers
Sites on the surface web are _____.
Westkost [7]
It’s A because surface website’s are available for everybody but the dark web is opposite

3 0
2 years ago
Read 2 more answers
Which of the following is NOT a common slide layout?
Kitty [74]
The answer is going to be story, for your question of the following that is not a common slide layout
3 0
2 years ago
Other questions:
  • To begin importing data from an excel spreadsheet, click on the ____ tab on the ribbon.
    11·1 answer
  • Given the following code segment, what is output after "result = "? int x = 1, y = 1, z = 1; y = y + z; x = x + y; cout &lt;&lt;
    7·1 answer
  • Describe a time when you influenced someone else’s knowledge around technology, whether it be an app, a new gadget, etc. What di
    14·1 answer
  • Draw the hierarchy chart and then plan the logic for a program that calculates a person’s body mass index (BMI).
    11·1 answer
  • Which type of network involves buildings in multiple cities connecting to each other?
    8·1 answer
  • How dose society use computer in government?​
    5·1 answer
  • You are hired by a game design company and one of their most popular games is The Journey. The game has a ton of quests, and for
    12·2 answers
  • How to convert meters to centimeters in c programming​
    8·1 answer
  • Compare the freedom available to the American media with the freedom available to media in other parts of the world. How does a
    8·1 answer
  • what is one benefit of placing voip gateways in geographically separated branch offices that have an existing wan connection?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!