Data Structure in C Please help ADT's

This is a discussion on Data Structure in C Please help ADT's within the C Programming forums, part of the General Programming Boards category; I started Data Structures and the professor doesnt know what he is doing. He took a project from another school ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    5

    Data Structure in C Please help ADT's

    I started Data Structures and the professor doesnt know what he is doing. He took a project from another school and gave it to us. I know how to program in C but never worked with ADT and binding its completely new to me. I figured out the .h files which is easy but can not understand how to make my .c files work with his "test code". I am attaching the project in a pdf file if anyone could help i would greatly appreciate it. At least point me in the right direction I know the .h files attach to the main and then my .c files attach to the .h files I already made. Thank you anyone that can help.
    Attached Images Attached Images

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you know that "the .h files attach to the main and then my .c files attach to the .h files" you know way more than the rest of us. I don't even know what that means, let alone that it's true.

    In the attached document, your instructor appears to be using the word "binding" where I might use the word "(ordered) pair" -- he just means that the key and the value are associated together and shouldn't ever be split apart.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    39
    Do you have a textbook or use other sources to help as well?

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    5
    Yes i have the text book it doesnt help. he has not discussed the project much just threw it at us. Even another student that I showed this project to that took the course last semester, but with a different professor, did not even know what it is asking for.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,602
    Just to check: you have written the header file and implementation, but now the problem is that you do not know how to get your implementation to work with your instructor's sample tests?

    If so, what do the sample tests consist of?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    5
    We are supposed to use GCC compiler. I am new to Data Structures I am ok in C. I really dont even understand the implementation part of it.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,602
    Quote Originally Posted by slim3883
    We are supposed to use GCC compiler. I am new to Data Structures I am ok in C. I really dont even understand the implementation part of it.
    Okay, so you have not started at all?

    What I would do is to define a structure. Reading the section of how to implement this data structure, it is clear that I would need a pointer so that I can do dynamic memory allocation. It is also clear that I need to keep track of the capacity (number of elements allocated) and the size (number of elements in use) so that I can expand the dynamic array when needed.

    So, we are faced with a problem: what type should this pointer be? Looking at the requirements for Set_getValue(), we see that it returns a void*. Right, maybe we can use a pointer to void*. Next, in order to modify the set and to avoid unnecessary copying, we most likely should make Set_T a pointer type. Consequently, we might start by defining:
    Code:
    struct Set
    {
        void **data;
        size_t capacity;
        size_t size;
    };
    
    typedef struct Set* Set_T;
    From here, think of how you might implement Set_new(). Do not be afraid to modify the definition of the structure that I showed.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    5
    ok So I posted the test code. This is what I had for Set_new()


    Code:
    Set_T set = malloc (sizeof(Set_T));
      return set;
    I had the struct sort of like yours in my setInterface.h like this

    Code:
      typedef struct {
         ItemType key;
         ItemType value;
    
      } Set_T;
    because I thought that each struct would have a key and value so I know I might be wrong. I really appreciate this help though let me know if you see if what I am doing is wrong. Thanks
    Attached Files Attached Files

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,602
    Quote Originally Posted by slim3883
    because I thought that each struct would have a key and value so I know I might be wrong.
    Be more confident. You have the right idea, but the problem is that you have defined a structure appropriate for a key/value pair, not a set (or rather, a map; the terminology used by the assignment is not accurate in that sense).

    So, what you need to do is to have a dynamic array of key/value pairs.

    Quote Originally Posted by slim3883
    This is what I had for Set_new()
    That would be wrong. Set_new is supposed to initialise the set.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    5
    I appreciate the help. I will keep working on it and see if I can figure it all out. If there are any other ideas you might have or things you think I might need to know please tell me. This project is very overwhelming for me

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread question how would I init this data structure?
    By mr_coffee in forum C Programming
    Replies: 2
    Last Post: 02-23-2009, 11:42 AM
  2. Data structure implementation
    By fkheng in forum C Programming
    Replies: 3
    Last Post: 07-31-2003, 07:44 AM
  3. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 05:03 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Dynamic Data Structure -- Which one is better?
    By Yin in forum C++ Programming
    Replies: 0
    Last Post: 04-10-2002, 11:38 PM

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