help me to understand this method

This is a discussion on help me to understand this method within the C Programming forums, part of the General Programming Boards category; Here's the description in the .h file Code: /* Construct a dictionary of words. When you create it, you may ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 06:50 PM
  2. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-07-2008, 11:30 PM
  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, 03:22 PM

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