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]
3 years ago
10

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

Computers and Technology
1 answer:
andrew11 [14]3 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
Your boss has asked you to create a customized letterhead for the business, "Boyne Mountain Ski Shop". Explain how to create the
lakkis [162]

Creating a letter head is very simple. However, you need to do some planning. You are required to pick a size and shape accordingly. I would prefer a landscape oriented rectangle. Select a theme appropriate and consistent with the traits of you company. Personalize with a simple and sleek image that can be printed easily if necessary. Select a font that is bold enough, readable, and eye catching. You can include items like a slogan, a name, phone numbers, address, email address, a link to you web address and the established dates.

5 0
3 years ago
Victor has been murdered, and Art, Bob, and Carl are suspects. Art says he did not do it. He says that Bob was the victim's frie
-BARSIC- [3]

Answer:

Bob

Explanation:

we can use symbolic reasoning to prove that Bob is not innocent without enumerating all of the cases.

6 0
3 years ago
You want to view a list of users on a linux system. what command should you use?
vredina [299]
Answer is A: cat /use/passwd
7 0
2 years ago
What may happen if a large number of computer users are attempting to access a web site at the same time that you are?
Maurinko [17]
A. You may be unable to link to the site.
<span />
4 0
3 years ago
HELP PLEASE True or False? A human is needed to create algorithms that computers use
AveGali [126]
I guess true but also false if technology develops more to write it’s own algorithms.
3 0
3 years ago
Read 2 more answers
Other questions:
  • python (Financial application: compute the future investment value) Write a function that computes a future investment value at
    5·1 answer
  • Woodchucks are classified in the same family as squirrels,but in a different family than mice.Do woodchuck have more in common w
    8·1 answer
  • Write a program that opens a text le called quiz.txt for reading. This le contains a single line with a student's rst name then
    15·1 answer
  • A résumé can be delivered through _____.a.
    9·2 answers
  • Write a function named get_my_age that returns your age as an int (this is YOUR age, so if you were 21 you would return the numb
    11·1 answer
  • If a computer is found to have an ip address of 169.254.1.1, what can you assume about how it received that ip address?
    11·1 answer
  • When backing up a database server to LTO tape drives, the following schedule is used. Backups take one hour to complete.
    12·1 answer
  • Budget at completion<br><br> What does this measurement tell you?
    8·1 answer
  • Look at the following code:
    7·1 answer
  • Software engineers typically use UML as a principle means of explaining design. UML stands for:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!