Thread: Sorting by Insertion

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    4

    Cool Sorting by Insertion

    Whats wrong?

    void sort()
    {
    int z, i;
    for(i = 1; i <= z - 1; i++)
    {
    int x = i;

    while((j > 0) && (array[x] < array[x - 1]))
    {
    swap(array[x], array [x - 1]);
    x--;
    }
    }

    its says : illegal structure

    thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    This
    swap(array[x], array [x - 1]);

    Should be?
    swap( &array[x], &array[x-1] );

    Hard to say without more code

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    4
    no joy with that, caused heaps more errors, can I mail the code, I cannot post it I'm afraid.

    thanks for the help

  4. #4
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,227
    why be afraid? noone will steal your code, insertion sort algorithms are widly avaiable over the net...and all I think we'd need to look at is your struct declaration...but like Salem said, it's hard to tell without more code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick, Partiotion, and Insertion Sort
    By silicon in forum C++ Programming
    Replies: 0
    Last Post: 05-18-2005, 08:47 PM
  2. Do you know...
    By davejigsaw in forum C++ Programming
    Replies: 1
    Last Post: 05-10-2005, 10:33 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. How do i use Insertion for sorting?
    By kenny3b in forum C++ Programming
    Replies: 2
    Last Post: 03-29-2003, 10:48 AM