The Insertion Sort - C++ source code

By Sergey Skudaev

++++

Precondition: The function accepts an unsorted array and integer size that is the size of the array.

Post condition: Sorted array

void insertionSort ( int array[], int size)
{
    int current = 1;
    int temp;
    int walker;

        while (current < size)
        {
          temp = array [current];
          walker = current -1;

                while (( walker >= 0 )&&( temp < array [walker] ))
                {
                array[walker +1] = array[walker];
                walker = walker -1;
                }

            array [walker+1] = temp;
            current = current + 1;
         }

}

Demo Applet

Did you find information useful?
Send to your friend a link to this page

Please rate the tutorial

1 2 3 4 5 6 7 8 9 10



Learn Visual Basic 6.0 [Kindle Edition] $1.99

How to Build Your Own Web Site from Scratch [Kindle Edition] $1.99

Comments
 
Register to add comments ( 1000 char ) for insertcpp.php.