Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1036
  • Last Modified:

Beginner issues with insertion sort using an array

I am making a rookie mistake but I just can't seem to figure out what I am doing wrong. The compiler issue is regarding when I call the insertion sort function in main and am passing in the array.  I know you pass in the array and its size separately but I'm doing something wrong and would love to know if you can help me finish this mini test program so it compiles successfully. i am trying to learn about sorting algorithms. Thanks

#include <iostream>

using namespace std;

void insertion_sort(int x[],int length)
{
    int key,i;
    for(int j=1; j<length; j++)
    {
        key=x[j];
        i=j-1;
        while(x[i]>key && i>=0)
        {
            x[i+1]=x[i];
            i--;
        }
        x[i+1]=key;
    }
}

int main()
{
    int a[6] = {5,2,4,6,1,3};
    int arraySize = sizeof(a)/sizeof(a[0]);
    cout << arraySize;

    cout << insertion_sort(a, arraySize);
    return 0;
}

Open in new window

0
Mark_Co
Asked:
Mark_Co
1 Solution
 
momi_sabagCommented:
you did not specify what the error is
but maybe it is because you try to cout a function that returns void?
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now