From a8ae18828b17f06211c00c327f0bed070e4b40a1 Mon Sep 17 00:00:00 2001 From: wjf-hs Date: Thu, 20 Jun 2024 15:04:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=A4=A7=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=EF=BC=8C=E5=87=86=E5=A4=87=E5=85=BC=E5=AE=B9=E4=BB=BB=E6=84=8F?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datastruct/list.c | 109 +++++++++++++++++++++++++++++++++++++++++++++ datastruct/list.h | 2 +- datastruct/stack.c | 3 +- 3 files changed, 111 insertions(+), 3 deletions(-) diff --git a/datastruct/list.c b/datastruct/list.c index a2bd94e..e863e35 100644 --- a/datastruct/list.c +++ b/datastruct/list.c @@ -360,3 +360,112 @@ void list_test(void) #endif + +// kernel +bool list_append(struct _list* self, void* obj) +{ + +} + +bool list_clear(struct _list* self) +{ + +} + +bool list_empty(struct _list* self) +{ + +} + +uint32_t list_index(struct _list* self, void* obj) +{ + +} + +bool list_insert(struct _list* self, uint32_t index, void* obj) +{ + +} + +bool list_pop(struct _list* self, uint32_t index, void* obj) +{ + +} + +bool list_at(struct _list* self, uint32_t index) +{ + +} + +bool list_set(struct _list* self, uint32_t index, void* obj) +{ + +} + +uint32_t list_size(struct _list* self) +{ + +} + +bool list_remove(struct _list* self, uint32_t index) +{ + +} + +bool list_reverse(struct _list* self) +{ + +} + +bool list_sort(struct _list* self, uint8_t reserve, int (*compare)(void* obj, void* obj2)) +{ + +} + +// free +void list_destory(struct _list* self) +{ + +} + +// print +void list_print(struct _list* self) +{ + +} + +bool list_init(struct _list* list, uint32_t obj_size) +{ + assert(list != NULL); + + // 1. set attr + list->_obj_size = obj_size; + list->_size = 0; + list->_capacity = 64; + list->_ratio = 2; + + // 2. set function + // kernel + list->append = list_append; + list->at = list_at; + list->clear = list_clear; + list->destory = list_destory; + list->empty = list_empty; + list->index = list_index; + list->insert = list_insert; + list->pop = list_pop; + list->print = list->print; + list->remove = list->remove; + list->reverse = list->reverse; + list->set = list->set; + list->size = list->size; + list->sort = list->sort; + + // 3. set array + list->obj = (void*)calloc(list->_capacity, list->_obj_size); + if (list->obj == NULL) + { + return false; + } + return true; +} diff --git a/datastruct/list.h b/datastruct/list.h index 8cf9a8f..3c01f2d 100644 --- a/datastruct/list.h +++ b/datastruct/list.h @@ -82,7 +82,7 @@ struct _list void (*print_obj)(void* obj); }; -bool list_init(struct _list *l); +bool list_init(struct _list* list, uint32_t obj_size); #endif diff --git a/datastruct/stack.c b/datastruct/stack.c index ec5bb7d..494dad8 100644 --- a/datastruct/stack.c +++ b/datastruct/stack.c @@ -261,8 +261,7 @@ bool stack2_init(struct _stack* s, uint32_t obj_size) // 1. set attr s->_obj_size = obj_size; s->_size = 0; - // s->_capacity = 64; - s->_capacity = 3; + s->_capacity = 64; s->_ratio = 2; // 2. set function