Пример #1
0
void dlist_foreach_reverse_udata( struct dlistnode** list, dlist_foreach_udata_func_type func, void* udata )
{
    struct dlistnode* node = dlist_last(*list);
    while( node ) {
	struct dlistnode* t = node;
	node = node->prev;
	func( t, udata );
    }
}
Пример #2
0
void  *queue_pop (Queue *queue)
{
        if (queue->tail == NULL)
                return NULL;
        void *tailTempData = ((queue->tail)->data);
        queue->tail = (queue->tail)->previous;
        queue->head = dlist_delete_link(queue->head, dlist_last(queue->head));
        return (tailTempData);
       
}
Пример #3
0
dlist *
dlist_add(dlist *l, void *d)
{
	dlist *new_elem;
	
	l = dlist_last(l);
	new_elem = malloc(sizeof(dlist));
	new_elem->prev = l;
	new_elem->next = 0;
	new_elem->data = d;
	if(l)
		l->next = new_elem;
	return new_elem;
}
Пример #4
0
void
dlist_reverse(dlist *l)
{
	dlist *iter1 = dlist_first(l),
		*iter2 = dlist_last(l);
	
	while(iter1 != iter2) {
		dlist_swap(iter1, iter2);
		if(iter1->next == iter2)
			break;
		iter1 = iter1->next;
		iter2 = iter2->prev;
	}
}
Пример #5
0
/**
 * @brief Concatinates two lists together
 * @param list1 The first half of the list
 * @param list2 The second half of the list
 * @return The new list list
 */
struct dlist *dlist_concat(struct dlist *list1, struct dlist *list2)
{
	struct dlist *tmp = NULL;

	if (list2) {
		tmp = dlist_last(list1);
		if (tmp) {
			tmp->next = list2;
		}
		else
			list1 = list2;
		list2->prev = tmp;
	}

	return list1;	
}
Пример #6
0
/**
 * @brief Append a list element to the end of the list
 * @param list The list list pointer
 * @param data The data to add to the list
 * @return The new list list
 */
struct dlist *dlist_append(struct dlist *list, void *data)
{
	struct dlist *last = NULL;
	struct dlist *next = dlist_alloc();

	next->data = data;
	next->next = NULL;

	if (list) {
		last = dlist_last(list);
		last->next = next;
		next->prev = last;
		return list;
	}
	else {
		next->prev = NULL;
		return next;
	}
}
Пример #7
0
struct dlistnode* dlist_popback( struct dlistnode** list ) {
    struct dlistnode* node = dlist_last(*list);
    if( node )
	dlist_erase( list, node );
    return node;
}