mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-03 23:56:54 +08:00
先添加通用列表的结构体,方便后续实现功能。
This commit is contained in:
parent
fe82a85764
commit
2e31e1234d
@ -14,7 +14,7 @@
|
||||
#define RAVLTREE 0 // avl tree by recursion
|
||||
#define QUEUE 0
|
||||
#define STACK 1
|
||||
#define LIST 0
|
||||
#define LIST 1
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
|
@ -167,6 +167,7 @@ void list_traversal_reversed(plist_t list, list_data_disp_t disp)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
bool list_init(list_t list)
|
||||
{
|
||||
// list->capacity = 64;
|
||||
@ -356,3 +357,6 @@ void list_test(void)
|
||||
list_print(&list);
|
||||
list_destory(&list);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -39,35 +39,50 @@ void list_traversal_reversed(plist_t list, list_data_disp_t disp);
|
||||
extern void list_test(void);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef LIST
|
||||
|
||||
typedef int list_data_t;
|
||||
|
||||
struct _list
|
||||
{
|
||||
list_data_t * array; // 数组(存储列表元素)
|
||||
int capacity; // 列表容量
|
||||
int size; // 列表大小
|
||||
int extend_ratio; // 列表每次扩容的倍数
|
||||
void * obj;
|
||||
uint32_t _obj_size; // 元素大小
|
||||
uint32_t _size; // 栈大小
|
||||
uint32_t _capacity; // 总容量
|
||||
uint32_t _ratio; // 扩展比率
|
||||
|
||||
// kernel
|
||||
bool (*append)(struct _list* self, void* obj);
|
||||
|
||||
bool (*clear)(struct _list* self);
|
||||
|
||||
bool (*empty)(struct _list* self);
|
||||
|
||||
uint32_t (*index)(struct _list* self, void* obj);
|
||||
|
||||
bool (*insert)(struct _list* self, uint32_t index, void* obj);
|
||||
|
||||
bool (*pop)(struct _list* self, uint32_t index, void* obj);
|
||||
|
||||
bool (*at)(struct _list* self, uint32_t index);
|
||||
|
||||
bool (*set)(struct _list* self, uint32_t index, void* obj);
|
||||
|
||||
uint32_t(*size)(struct _list* self);
|
||||
|
||||
bool (*remove)(struct _list* self, uint32_t index);
|
||||
|
||||
bool (*reverse)(struct _list* self);
|
||||
|
||||
bool (*sort)(struct _list* self, uint8_t reserve, int (*compare)(void* obj, void* obj2));
|
||||
|
||||
// free
|
||||
void (*destory)(struct _list* self);
|
||||
|
||||
// print
|
||||
void (*print)(struct _list* self);
|
||||
void (*print_obj)(void* obj);
|
||||
};
|
||||
typedef struct _list * list_t;
|
||||
|
||||
bool list_init(list_t list);
|
||||
void list_destory(list_t list);
|
||||
|
||||
bool list_empty(list_t list);
|
||||
int list_size(list_t list);
|
||||
|
||||
bool list_insert(list_t list, int index, list_data_t data);
|
||||
bool list_append(list_t list, list_data_t data);
|
||||
list_data_t list_delete(list_t list, int index);
|
||||
bool list_clear(list_t list);
|
||||
list_data_t list_get(list_t list, int index);
|
||||
bool list_set(list_t list, int index, list_data_t data);
|
||||
|
||||
extern void list_test(void);
|
||||
bool list_init(struct _list *l);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -12,20 +12,21 @@ struct _stack_node
|
||||
struct _stack
|
||||
{
|
||||
struct _stack_node * _head;
|
||||
uint32_t _capacity; // ×ÜÈÝÁ¿ for array
|
||||
uint32_t _ratio; // À©Õ¹±ÈÂÊ for array
|
||||
uint32_t _size; // 栈大小
|
||||
uint32_t _obj_size; // 元素大小
|
||||
|
||||
// base
|
||||
uint32_t(*size)(struct _stack* s);
|
||||
bool (*empty)(struct _stack* s);
|
||||
// only for array mode
|
||||
uint32_t _capacity; // ×ÜÈÝÁ¿
|
||||
uint32_t _ratio; // À©Õ¹±ÈÂÊ
|
||||
|
||||
// kernel
|
||||
bool (*peek)(struct _stack* s, void* obj);
|
||||
bool (*push)(struct _stack* s, void* obj);
|
||||
bool (*pop)(struct _stack* s, void* obj);
|
||||
|
||||
// base
|
||||
uint32_t(*size)(struct _stack* s);
|
||||
bool (*empty)(struct _stack* s);
|
||||
|
||||
// others
|
||||
bool (*clear)(struct _stack* s);
|
||||
void (*destory)(struct _stack* s);
|
||||
|
Loading…
Reference in New Issue
Block a user