Jump to content
  • Advertisement
  • Remove ads and support GameDev.net for only $3. Learn more: The New GDNet+: No Ads!

  • 09/13/99 06:21 PM
    Sign in to follow this  

    Insertion Sort

    General and Gameplay Programming

    Myopic Rhino
    The basic step in this algorithm is to insert a data set into a sequence of ordered (increasing) data sets in such way that the resulting sequence of data set is also ordered. Thus if the data set D is inserted in position i, then the data sets in position j less than i will be less than D, and the data sets in position j greater than i will be greater than D.

    Since we will be manipulating the data sets in an array, we will have to compare all of the values of the data and move them once the ordering relationship between two values are determined. Below is the pseudo-code of the algorithm.

    [font="Verdana, Tahoma, Arial"][size="2"]Insertion Sort (Sorting the array A[size])

    For index i = 2 up to i = size
    While before reach the end of cells
    Compare the element Awith the preceding element (A[i - 1]).
    If the element is smaller than the preceding one (A < A[i - 1]),
    swap them;
    else, go to the next element.

    [font="Courier New, fixedsys"][size="2"][color="#000088"] [/color][/font][/font]

      Report Article
    Sign in to follow this  

    User Feedback

    There are no comments to display.

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!