示例#1
0
struct mlistelem * mlist_replace(mlist_t list, void *data)
{
	struct mlistelem *e;
	
	e = mlist_get(list,data);
	if (e == NULL)
		return NULL;

	memcpy(mlistelem_dataptr(e), data,list->data_size);
	return e;

}
示例#2
0
文件: mlist.c 项目: mindbergh/mlib
MList* mlist_insert(MList* list, void* data, int position) {
    MList *new_list;
    MList *tmp_list;

    if (position < 0)
        return mlist_append(list, data);
    else if (position == 0)
        return mlist_prepend(list, data);

    tmp_list = mlist_get(list, position);
    if (!tmp_list)
        return mlist_append (list, data);

    new_list = mlist_new();
    new_list->data = data;
    new_list->prev = tmp_list->prev;
    tmp_list->prev->next = new_list;
    new_list->next = tmp_list;
    tmp_list->prev = new_list;

    return list;
}