The type definition of the list is in linkedList.h as usual.
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
typedef struct snode {
int value;
struct snode *next;
} snodeType;
typedef struct hnode {int count;
snodeType *first;
snodeType *last;
} sList;
sList* create_sList(void);
int insert_element_s(sList *L, snodeType *p, int value);
int delete_element_s(sList *L, snodeType *p);
sList* merge_lists(sList *L1, sList *L2);
#endif /* LINKEDLIST_H */
Question is:
sList * create_sList(void) creates the list and returns it to the caller. It has to allocate memory for the header node, initialize the fields in the struct hnode.
sList* create_sList(void) {
sList *list = NULL;
list->first = (sList*)malloc(sizeof(snodeType));
list->last = (sList*)malloc(sizeof(snodeType));
/* 2nd option
sList *list = NULL;
node = malloc(sizeof(snodeType));
node->next= NULL;
list->first = node;
list->last = node;
*/
return list;
}
I need to just initiate this linked list, is there somebody who know how?
sList* create_sList(void) { sList *list = malloc(sizeof(*list)); list->count = 0; list->last = list->first = NULL; return list; }
– BLUEPIXY Sep 21 '16 at 11:41