From bf0fe6c75ad81f0e88786a15bd1f253dd2fbdc8c Mon Sep 17 00:00:00 2001 From: jf-home Date: Thu, 20 Jun 2024 22:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=8C=E7=AB=AF=E9=98=9F?= =?UTF-8?q?=E5=88=97=EF=BC=8C=E7=94=A8=E5=8F=8C=E5=90=91=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E9=93=BE=E8=A1=A8=E5=AE=9E=E7=8E=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- datastruct/datastruct.vcxproj | 3 + datastruct/datastruct.vcxproj.filters | 9 ++ datastruct/deque.c | 113 ++++++++++++++++++++++++++ datastruct/deque.h | 56 +++++++++++++ datastruct/deque_test.c | 7 ++ 5 files changed, 188 insertions(+) create mode 100644 datastruct/deque.c create mode 100644 datastruct/deque.h create mode 100644 datastruct/deque_test.c diff --git a/datastruct/datastruct.vcxproj b/datastruct/datastruct.vcxproj index def2186..de9ae8a 100644 --- a/datastruct/datastruct.vcxproj +++ b/datastruct/datastruct.vcxproj @@ -143,6 +143,8 @@ + + @@ -159,6 +161,7 @@ + diff --git a/datastruct/datastruct.vcxproj.filters b/datastruct/datastruct.vcxproj.filters index 0d59ba4..4b77ada 100644 --- a/datastruct/datastruct.vcxproj.filters +++ b/datastruct/datastruct.vcxproj.filters @@ -54,6 +54,12 @@ 测试 + + 源文件 + + + 测试 + @@ -83,5 +89,8 @@ 头文件 + + 头文件 + \ No newline at end of file diff --git a/datastruct/deque.c b/datastruct/deque.c new file mode 100644 index 0000000..8d39b3d --- /dev/null +++ b/datastruct/deque.c @@ -0,0 +1,113 @@ + +#include "deque.h" + +bool deque_push_back(struct _list* self, void* obj) +{ + +} +bool deque_push_front(struct _list* self, void* obj) +{ + +} +bool deque_pop_back(struct _list* self, void* obj) +{ + +} +bool deque_pop_front(struct _list* self, void* obj) +{ + +} +bool deque_back(struct _list* self, void* obj) +{ + +} +bool deque_front(struct _list* self, void* obj) +{ + +} + +bool deque_insert(struct _list* self, int index, void* obj) +{ + +} +bool deque_erase(struct _list* self, int index, void* obj) +{ + +} + +int deque_index(struct _list* self, void* obj) +{ + +} +bool deque_remove(struct _list* self, void* obj) +{ + +} + +bool deque_clear(struct _list* self) +{ + +} + +bool deque_get(struct _list* self, int index, void* obj) +{ + +} +bool deque_set(struct _list* self, int index, void* obj) +{ + +} + +uint32_t deque_size(struct _list* self) +{ + +} +bool deque_empty(struct _list* self) +{ + +} +void deque_destory(struct _list* self) +{ + +} + +void deque_print(struct _list* self) +{ + +} + +bool deque_init(struct _deque* deque, uint32_t obj_size) +{ + // attribute + deque->_obj_size = obj_size; + deque->_size = 0; + // deque->_capacity = 64; + // deque->_ratio = 2; + + // function + deque->back = deque_back; + deque->clear = deque_clear; + deque->destory = deque_destory; + deque->empty = deque_empty; + deque->erase = deque_erase; + deque->front = deque_front; + deque->get = deque_get; + deque->index = deque_index; + deque->insert = deque_insert; + deque->pop_back = deque_pop_back; + deque->pop_front = deque_pop_back; + deque->remove = deque_remove; + deque->set = deque_set; + deque->size = deque_size; + + + deque->_head = (struct _deque_node*)malloc(sizeof(struct _deque_node)); + if (deque->_head == NULL) + { + return false; + } + deque->_head->prev = deque->_head; + deque->_head->next = deque->_head; + + return true; +} diff --git a/datastruct/deque.h b/datastruct/deque.h new file mode 100644 index 0000000..a109805 --- /dev/null +++ b/datastruct/deque.h @@ -0,0 +1,56 @@ + +#ifndef _DEQUE_H_ +#define _DEQUE_H_ + +#include "common.h" + +struct _deque_node +{ + void* obj; + struct _deque_node* prev; + struct _deque_node* next; +}; + +struct _deque +{ + struct _deque_node* _head; + + uint32_t _obj_size; // ԪشС + uint32_t _size; // ջС + uint32_t _capacity; // + uint32_t _ratio; // չ + + // kernel + bool (*push_back)(struct _list* self, void* obj); + bool (*push_front)(struct _list* self, void* obj); + bool (*pop_back)(struct _list* self, void* obj); + bool (*pop_front)(struct _list* self, void* obj); + bool (*back)(struct _list* self, void* obj); + bool (*front)(struct _list* self, void* obj); + + bool (*insert)(struct _list* self, int index, void* obj); + bool (*erase)(struct _list* self, int index, void* obj); + + int (*index)(struct _list* self, void* obj); + bool (*remove)(struct _list* self, void* obj); + + bool (*clear)(struct _list* self); + + bool (*get)(struct _list* self, int index, void* obj); + bool (*set)(struct _list* self, int index, void* obj); + + // size + uint32_t(*size)(struct _list* self); + bool (*empty)(struct _list* self); + + // free + void (*destory)(struct _list* self); + + // print + void (*print)(struct _list* self); + void (*print_obj)(void* obj); +}; + +bool deque_init(struct _deque* deque, uint32_t obj_size); + +#endif diff --git a/datastruct/deque_test.c b/datastruct/deque_test.c new file mode 100644 index 0000000..794a844 --- /dev/null +++ b/datastruct/deque_test.c @@ -0,0 +1,7 @@ + +#include "deque.h" + +void deque_test(void) +{ + +}