Thread: help me to understand this method

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    help me to understand this method

    Here's the description in the .h file

    Code:
    /* Construct a dictionary of words.  When you create it, you may request
    ** the dictionary keep the dictionary in sorted order (or not) for
    ** iteration **/
    typedef enum { UNSORTED_ORDER, SORTED_ORDER } sorted_e;
    Words* DictionaryConstruct (sorted_e sorted);
    and more info in the .c file

    Code:
    Words* DictionaryConstruct (sorted_e sorted)
    {
      /* TODO:  Don't use the the sorted_e ... should we ?  Right now
      ** we always keep everything sorted, but we can make things
      ** faster if we don't have to keep them sorted... */
      if (sorted==UNSORTED_ORDER) {
        /* ?? */
      } 
    
      Words* dummy = (Words*) malloc(sizeof(Words));
      dummy->next = 0;
      dummy->word = 0;
      dummy->count = -1;  /* Value to show we are at dummy node */
      return dummy;
    }
    I don't quite understand what does the UNSORTED_ORDER and SORTED does here?? Say I have a file that is sorted and I call the function createDictionary on it then what does it do?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    sorted order supposes that adding new word should be accomplished using search of the appropriate location where to put it to maintain dictionary sorted

    sorted dictionary gives a possibility of the binary search (long insert, quick access)
    unsorted dictionary adds words at the begining or at the end (what is more suitable) - so insert operation is quick, search could take longer
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    so the first dictionary I should have it is unsorted... and then the second dictionary to be checked if the data exists in the same dictionary or not should be a sorted list..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 07:50 PM
  2. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-08-2008, 12:30 AM
  3. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM
  4. Overriding a method in C
    By DavidDobson in forum C Programming
    Replies: 1
    Last Post: 07-05-2008, 07:51 AM
  5. Replies: 2
    Last Post: 01-22-2008, 04:22 PM