Beginner issues with insertion sort using an array

Posted on 2012-09-07
Last Modified: 2012-09-08
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++)
        while(x[i]>key && i>=0)

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

Question by:Mark_Co
    1 Comment
    LVL 37

    Accepted Solution

    you did not specify what the error is
    but maybe it is because you try to cout a function that returns void?

    Featured Post

    Live - One-on-One C++ Help from Top Experts

    Solve your toughest problems, fast.
    C++ experts are online now and ready to help you.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Hibernate methods 2 45
    EvenOdd challenge 10 68
    scoreUp challenge 14 40
    Math question 3 35
    Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now