0

I want to implement the structure on the image in C language. But I have a problem because the 2 structures created call each other and therefore pose a problem how can I remedy it?

set data structure picture : Imgur link

liste set :

typedef struct liste_set
{
    set *head;
    set *tail;
} liste_set;

set :

typedef struct set set;
struct set
{
    int value;
    liste_set *liste;
    set *next;
};

Thank you for your help.

3
  • Note that with a circular list, pointer tail provides for O(1) access to tail&head - head is just tail->next. Commented Oct 8, 2022 at 20:14
  • This looks like a linked list, not a disjoint set structure Commented Oct 8, 2022 at 21:15
  • @greybeard Wrong because tail->next is NULL for accessing head we need to do tail->liste->head but I see what you mean ;) Commented Oct 8, 2022 at 22:35

1 Answer 1

1

All you have to do is have preceeding declerations so the compiler knows what set is even before you actually fully declare it.

// declare structs
struct liste_set;
struct set;

// typedef struct x to just x
typedef struct liste_set liste_set;
typedef struct set set;

// describe what the structs are
struct liste_set
{
    set *head;
    set *tail;
};

struct set
{
    int value;
    liste_set *liste;
    set *next;
};

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.