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
You would like to create a graph that shows how much of your total investments are in stocks, savings, and mutual funds. You sho
sdas [7]
The answer is D. line graph
4 0
3 years ago
Read 2 more answers
Complete the AscendingAndDescending application so that it asks a user to enter three integers. Display them in ascending and de
Andreas93 [3]

Answer:

Following are the solution to the given question:

import java.util.Scanner;//import package

public class AscendingAndDescending//defining a class AscendingAndDescending  

{

   public static void main(String[] args) //main method

   {

       int n1,n2,n3,min,max,m;

       Scanner in = new Scanner(System.in);//creating Scanner class object

       System.out.print("Enter an integer: ");//print message

       n1 = in.nextInt();//input value

       System.out.print("And another: ");//print message

       n2 = in.nextInt();//input value

       System.out.print("And just one more: ");//print message

       n3 = in.nextInt();//input value

       min = n1; //use min variable that holds value

       max = n1; //use mix variable that holds value

       if (n2 > max) max = n2;//use if to compare value and hols value in max variable

       if (n3 > max) max = n3;//use if to compare value and hols value in max variable

       if (n2 < min) min = n2;//use if to compare value and hols value in min variable

       if (n3 < min) min = n3;//use if to compare value and hols value in min variable

       m = (n1 + n2 + n3) - (min + max);//defining m variable that arrange value

       System.out.println("Ascending: " + min + " " + m + " " + max);//print Ascending order value

       System.out.println("Descending: " + max + " " + m + " " + min);//print Descending order value

   }

}

Output:

Enter an integer: 8

And another: 9

And just one more: 7

Ascending: 7 8 9

Descending: 9 8 7

Explanation:

In this program inside the main method three integer variable "n1,n2, and n3" is declared that inputs value from the user end and also defines three variable "min, max, and m" that uses the conditional statement that checks inputs value and assigns value according to the ascending and descending order and prints its values.

5 0
3 years ago
Jeremy is working with a team that is creating an application using attributes and associated methods. What type of programming
Ugo [173]
<span>object-oriented programming languages</span>
8 0
2 years ago
Order the steps to use a logical argument as a rule type.
muminat

Answer:

Click home tab, click conditional formatting, click new rule, use formula to determine

6 0
2 years ago
Read 2 more answers
Write a program that will take an integer and add up each of the number’s digits, count the number of digits in the number, and
Inga [223]
For count digits, you could just convert it to a String and check the length
Sum digits, convert to string then seperate each character with charAt then convert it to numbers in the return statement.
Average digits you can convert it to a String and then convert them back after taking them apart.
5 0
2 years ago
Read 2 more answers
Other questions:
  • Which data type uses more memory an integer or an unsigned integer?
    6·1 answer
  • 2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you
    11·1 answer
  • When should an individual consider entering parenthood?
    5·1 answer
  • A forensic investigator at a crime lab is performing a forensic analysis of a hard drive that was brought in by state troopers.
    10·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·2 answers
  • Select the correct answer.
    14·2 answers
  • Having friends who cause you stress can decrease your happiness, which can in turn
    13·2 answers
  • Could anyone help me with this assignment please?
    6·1 answer
  • Write a program that takes a string as an input. If the string entered is equal to
    9·1 answer
  • The federal communications commission oversees the programming of which entities?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!