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
Explain briefly how learning how to follow can make a person a good leader
Masja [62]

By  learning how to follow, one can  be a good leader because: Looking up to a leader and following them help to:

  • Keep one's ego in check and one can be able to be a good ego manager.
  • They create strong credibility.
  • They help use to focus our efforts for maximum impact.

<h3>How does being a good follower make you a good leader?</h3>

As a good follower, a person can be able to have the boldness and confidence to be able to respectfully talk about a lot of things with their leader if you see that you're not going in the right way.

Note that  one can trust your leader and this will boast up the spirit of your input and engagement in all.

Hence, By  learning how to follow, one can  be a good leader because: Looking up to a leader and following them help to:

  • Keep one's ego in check and one can be able to be a good ego manager.
  • They create strong credibility.
  • They help use to focus our efforts for maximum impact.

Learn more about good leader from

brainly.com/question/12522775

#SPJ1

3 0
2 years ago
Which Of the following components leads to slow computer performance when it becomes outdated
Scorpion4ik [409]

guess its d drivers , since u said wen it gets outdated


8 0
3 years ago
Read 2 more answers
Victoria is creating a brochure for her photography studio. She designed the layout and placed a photo in the center of the page
cestrela7 [59]

Assuming Victoria is using Adobe Photoshop to create her brochure, below are the steps she is required to follow.

She should first open the image on Photoshop, click on the image option and select duplicate just in case the resized image is not what she wants.

Still on the image option, she should select Image size. A screen will pop up at this point, indicating the image’s current size. For the purposes of image resizing, Victoria should select Pixel dimensions category.

She should be able to type her preferred dimensions for both the width and height. She should make sure ‘Constrain Proportions’ is unchecked to be able to type in separate values.

If she decides to use the photo editing program, she can simply click on the image, and if resize handles appear around it, she can click and drag those to the desired size.


3 0
3 years ago
Nina is trying to learn more about how computers work. She has repeatedly read that the motherboard is the "brain” of the comput
Lady bird [3.3K]

Its

Processes the data on the computer .

5 0
3 years ago
Read 2 more answers
Why should a user preview the document before printing?​
Margarita [4]
The user should preview a document first to make sure the layout is correct, so as not to waste paper if a font size or layout is incorrect.
5 0
3 years ago
Read 2 more answers
Other questions:
  • Does technology get in the way of learning ?<br> Help Meh ! ♥ Some ideas :D
    14·2 answers
  • When approved for a loan, an individual essentially applied for aid in the area of...
    15·1 answer
  • The ____________ mechanism consists of a lever arm attached to the mousetrap spring.
    15·1 answer
  • Extinction of a species is always a negative impact on the Earth.<br><br> True<br> False
    8·1 answer
  • Micheal has increased the contrast of the given picture. Which feature or menu option of a word processing program did he use? A
    15·1 answer
  • What resources can be shared over a computer network?
    12·2 answers
  • What X coordinate does the center of a game begin at?
    9·1 answer
  • What should you do if you forget your root password for MySQL?
    13·1 answer
  • Which computer was part of the first generation of computers?
    14·2 answers
  • Consider the following method.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!