Thread: Please help me with this sort algorithm

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    30

    Unhappy Please help me with this sort algorithm

    Fixed.
    Last edited by Qui; 03-11-2004 at 03:59 PM.

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: Please help me with this sort algorithm

    Originally posted by Qui
    Hi, I am having a little trouble with my sorting algorithm, it just stops after the first pass of the internal loop , could someone please look over this and tell me what I am doing wrong.

    Thanks Qui.

    Code:
    void sort(Holiday *pHoliday)
    {
    	for(pHoliday = Head; pHoliday != NULL; pHoliday = pHoliday->next)
    	{
    		for(pHoliday = Head; pHoliday != NULL; pHoliday = pHoliday->next)
    		{
    			if(pHoliday->price > pHoliday->next->price)
    				insert(pHoliday->next,pHoliday);
    		}
    	}
    }
    You are using the nested loops of the form:
    Code:
    for (i=0; i<lim; i++)
        for (i=0; i<lim; i++)
    You just overwrote the outer loop value with the inner loop value. Change one of them to another variable name
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    30
    Hi, yes I can see what you mean, unfortunately it doesnt make a difference I had it that way before and it didnt work so I tried it this way and it still doenst work. , there must be something.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    30
    Fixed
    Last edited by Qui; 03-11-2004 at 03:59 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with debug (bubble sort algorithm)
    By lbraglia in forum C Programming
    Replies: 5
    Last Post: 10-19-2007, 05:24 PM
  2. choosing right sort algorithm
    By Micko in forum C++ Programming
    Replies: 15
    Last Post: 05-29-2006, 10:38 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. Replies: 2
    Last Post: 05-06-2003, 08:34 AM
  5. Sort algorithm and an ugly error
    By Trauts in forum C++ Programming
    Replies: 7
    Last Post: 02-25-2003, 12:36 PM