Sorting by Insertion

This is a discussion on Sorting by Insertion within the C Programming forums, part of the General Programming Boards category; Whats wrong? void sort() { int z, i; for(i = 1; i <= z - 1; i++) { int x ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,453
    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,230
    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, 09:33 AM
  5. How do i use Insertion for sorting?
    By kenny3b in forum C++ Programming
    Replies: 2
    Last Post: 03-29-2003, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21