mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-18 03:51:35 +08:00
困了,不写了。明天继续
This commit is contained in:
parent
cfcf212f96
commit
09e082cc68
@ -76,7 +76,16 @@ bool deque_back(struct _deque* self, void* obj)
|
|||||||
|
|
||||||
bool deque_front(struct _deque* self, void* obj)
|
bool deque_front(struct _deque* self, void* obj)
|
||||||
{
|
{
|
||||||
|
assert(self != NULL);
|
||||||
|
assert(self->_head != NULL);
|
||||||
|
assert(obj != NULL);
|
||||||
|
|
||||||
|
if (self->empty(self))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memmove(obj, self->_head->prev->obj, self->_obj_size);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deque_insert(struct _deque* self, int index, void* obj)
|
bool deque_insert(struct _deque* self, int index, void* obj)
|
||||||
@ -143,7 +152,7 @@ void deque_print(struct _deque* self)
|
|||||||
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
struct _deque_node * node = self->_head->prev;
|
struct _deque_node * node = self->_head->prev;
|
||||||
while (node != self->_head->next)
|
for (uint32_t i = 0; i < self->size(self); i++)
|
||||||
{
|
{
|
||||||
self->print_obj(node->obj);
|
self->print_obj(node->obj);
|
||||||
node = node->next;
|
node = node->next;
|
||||||
|
@ -24,16 +24,26 @@ static void deque_test_num(void)
|
|||||||
{
|
{
|
||||||
dq.push_back(&dq, &data[i]);
|
dq.push_back(&dq, &data[i]);
|
||||||
|
|
||||||
dq.back(&dq, &temp);
|
dq.front(&dq, &temp);
|
||||||
|
printf("front = ");
|
||||||
printf("push_back = ");
|
|
||||||
dq.print_obj(&temp);
|
dq.print_obj(&temp);
|
||||||
printf("\tsize after push_back = %2d\n", dq.size(&dq));
|
|
||||||
|
dq.back(&dq, &temp);
|
||||||
|
printf("\tback = ");
|
||||||
|
dq.print_obj(&temp);
|
||||||
|
|
||||||
|
printf("\tsize = %2d\n", dq.size(&dq));
|
||||||
}
|
}
|
||||||
printf("----- print -----\n");
|
printf("----- print -----\n");
|
||||||
dq.print(&dq);
|
dq.print(&dq);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
dq.clear(&dq);
|
||||||
|
if (dq.empty(&dq))
|
||||||
|
{
|
||||||
|
printf("----- empty -----\n");
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
printf("----- pop -----\n");
|
printf("----- pop -----\n");
|
||||||
for (i = 0; i < len + 1; i++)
|
for (i = 0; i < len + 1; i++)
|
||||||
|
Loading…
Reference in New Issue
Block a user