0

I want to implement a data structure like this.What will be a good method to implement this.

enter image description here

Well i am trying to implement linkedlist for signals

structure for Msg data

struct dbcMsg_t
{
unsigned char*   message_id;
unsigned char*   message_name;
unsigned char*   message_len;
unsigned char*   message_sender;
unsigned char*   message_comment;
unsigned char*   message_attribute_list;
unsigned char*   message_transmitter_list;
struct sigMsg_t  *SIG_INFO;
};

structure for Signal data

struct sigMsg_t
{
unsigned char*   signal_name;  
unsigned int     signal_bit_start;
unsigned char    signal_bit_len;
unsigned char    signal_endianess;
unsigned char    signal_signedness;   
struct sigMsg_t  *SIG_INFO_NEXT;
}*start=NULL;

There will be an array of MSG DATA

struct dbcMsg_t *new_node[MAX_DBC];

I am confused on how to implement this?I mean how to insert and how to display?

4
  • the structure for msg data has a pointer to another msg data instead of signal data. I'm not sure if thats what you intended since the picture says otherwise Commented Nov 4, 2015 at 9:09
  • 1
    didn't you just implement it? I don't understand the question Commented Nov 4, 2015 at 9:10
  • A Message Data may contain a number of signals. That's why i created image like that. Nope i didn't implement it yet. Is the structure design correct? Commented Nov 4, 2015 at 9:20
  • Couldn't find no error in your code. Should work Commented Nov 4, 2015 at 9:31

1 Answer 1

1

Implement a standard linked list of signal data nodes and hold a pointer of head nodes in your message data node.

typedef struct sigMsg_t *Sig_ptr;
typedef struct sigMsg_t {
    unsigned char*   signal_name;  
    unsigned int     signal_bit_start;
    unsigned char    signal_bit_len;
    unsigned char    signal_endianess;
    unsigned char    signal_signedness;   
    Sig_ptr  SIG_INFO_NEXT;
}Sig_node;

typedef struct dbcMsg_t {
    unsigned char*   message_id;
    unsigned char*   message_name;
    unsigned char*   message_len;
    unsigned char*   message_sender;
    unsigned char*   message_comment;
    unsigned char*   message_attribute_list;
    unsigned char*   message_transmitter_list;
    Sig_ptr  SIG_INFO_HEAD;
} Message;

Since you asked how to implement insert and print functions:

void insert_to_list_end(Sig_ptr *list, Sig_node data) {
    Sig_ptr newnode, last = *list;
    newnode = (Sig_ptr)malloc(sizeof(Sig_node));
    /*  fill the new load with new data here
    newnode->message_id = data.message_id; 
    ...
    */
    newnode-> SIG_INFO_NEXT = NULL;
    if (last == NULL){
        *list = newnode;
    }//first node
    else{
        while (1) {
            if (last-> SIG_INFO_NEXT == NULL) {
                last-> SIG_INFO_NEXT = newnode;
                break;
            }
            last = last-> SIG_INFO_NEXT;
        }
    }
}

And print:

//prints whole list using printItem extern function
void print_list(Sig_ptr list) {
    //implement this print func for a node in your main file
    extern void PrintItem(Sig_node c); 

    Sig_ptr aux1, aux2;

    aux1 = list;
    while (aux1 != NULL) {
        PrintItem(aux1);
        aux2 = aux1->SIG_INFO_NEXT;
        aux1 = aux2;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Will insert function works correctly? newnode is of type Sig_ptr esp newnode->message_id = data.message_id;
my bad, I'll fix that. It should append a Sig_node, not Message

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.