Thread: trouble with hash function implementing

  1. #31
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by phantomotap View Post
    I started playing with a new style that incorporates a lot of common strategies and a lot of complaints specifically so that all persons reading the code would find something to like about and something to complain about.
    LOL
    Code:
        condition1
     && (condition2 || condition3)
    This is one situation where breaking before an operator imparts semantic meaning which reduces the time spent reasoning about existing code.
    Agreed, I actually do that one too sometimes. I say "sometimes", because I tend to write code in different situations with differing coding standards (personal vs work and different business units etc), and so I'm too used to just going with the style of whatever I'm programming for, more or less.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  2. #32
    Registered User
    Join Date
    Jul 2012
    Posts
    87
    I think I get it this time. The first * is the fact that my array type is a pointer (of type hockey_player), and the need for the 2nd * is the fact that when we pass an array in parameter, it must point to an address and only a ptr can point to address, which in this case for my bucket array, it's pointer to first elem. All this time I was looking @ pass by ptr to ptr when we actually need to MODIFY the ACTUAL ptr (from main), since we pass addresses by value so a copy of the actual head ptr is made w/ a new ptr pointing to those head ptrs (from main). That was what I couldn't see. Thanks again.

  3. #33
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    An array can never be passed by value. If you try, then you will get a pointer to its first element. But does that mean you need to have a pointer when passing an array? No. You can pass an array by reference, too. They both have their advantages and disadvantages (some discussion on it earlier if you're interested). Passing the array by address is fine for you. Just a little FYI there. Perhaps it might help you get a little insight.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #34
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I don't know what happend to the post I thought I made to you about this quite a while back, but basically this:
    Code:
        hockey_player* p_1_front = NULL;//ptr to the itms in each bucket(ie. the address in each arr indx to a list)
         hockey_player* p_2_front = NULL;
         hockey_player* p_3_front = NULL;
         hockey_player* p_4_front = NULL;
         hockey_player* p_5_front = NULL;
         hockey_player* p_6_front = NULL;
         hockey_player* p_7_front = NULL;
         hockey_player* p_8_front = NULL;
         hockey_player* p_9_front = NULL;
         hockey_player* p_10_front = NULL;
    
           hockey_player* bucket[10] = {p_1_front, p_2_front, p_3_front, p_4_front, p_5_front, p_6_front, p_7_front,
              p_8_front, p_9_front};
    Is the same as just doing:
    Code:
    hockey_player* bucket[10] = {NULL};
    You set 10 individual pointers to NULL, and then copy all those NULLs into your array pointers. Congratulations, you now have a very long winded way of initialising the array to all NULLs.
    There exists therafter, no link whatsoever between the array and those individual variables.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hash function to hash key into geographic coordinate
    By dominic_tran201 in forum C++ Programming
    Replies: 2
    Last Post: 02-11-2011, 10:03 AM
  2. trying to make a hash table......trouble w/ memory?
    By cuizy in forum C Programming
    Replies: 3
    Last Post: 05-11-2009, 04:47 PM
  3. A little trouble implementing a blur filter
    By omishompi in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2006, 08:57 AM
  4. Having trouble implementing enumeration.
    By RP319 in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2005, 07:03 PM