So i've never really worked with doubly linked lists in terms of coding, and I didn't do great with singly linked lists either. I have it all coded out but it's giving me a segmentation fault when I run it. I have looked over all my code and have no idea whats wrong, in add event i malloc one node of space then find where to add it and add it. i only add 1 per call to add event so that shouldnt be an issue. is there an initial part im missing when you first start the list?
[note all of the variables and definitions you see that aren't in the code are in one of the 2 external files if u need more info from them to help let me know.
osdefs.h
externs.hCode:struct event_list { /** Type of event. */ event_type event; /** User or device causing the event. */ int agent; /** Time event occurs. */ struct time_type time; /** Next event node in list. */ struct event_list* prev; /** Previous event node in list. */ struct event_list* next; }; typedef struct event_list event_list;
obj1.cCode:extern event_list* Event_List; ///< Pointer to head of event list
Code:void Add_Event( int event, int agent, struct time_type* time ) { //Header points to the head of the list. event_list* header = Event_List; event_list* temp; temp = malloc(sizeof(event_list)); temp->event = event; temp->agent = agent; temp->time.nanosec = time->nanosec; temp->time.seconds = time->seconds; temp->next = NULL; temp->prev = NULL; if(Event_List==NULL) { // header = temp; Event_List = temp; return; } //While header is not the last node in the list. while(header!=NULL){ //First compare the temporary nodes seconds to the header's seconds. If they are the same: //compare nanoseconds of each node, if we enter the loop then temp precedes header. if(temp->time.seconds < header->time.seconds || (temp->time.seconds == header->time.seconds && temp->time.nanosec <= header->time.nanosec)) { //Make temp the new head of the list. //temp->next now pointts to header. if(header->prev = NULL) { header->prev = temp; temp->next = header; temp->prev = NULL; Event_List = temp; header = NULL; } else { //Insert into the middle of the list. header->prev->next = temp; temp->prev = header->prev; header->prev = temp; temp->next = header; header = NULL; } }//end outer if //Inserting at the end of the list temp->previous is set as header. else if(header->next == NULL) { header->next = temp; temp->prev = header; temp->next = NULL; header = NULL; } //Advance the header to the next node in the list. else header=header->next; }//end while }



LinkBack URL
About LinkBacks


