mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-17 19:41:36 +08:00
先预留配置文件,如果后续用的上的话。
This commit is contained in:
parent
769f7040d2
commit
1f82b7502c
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -23,6 +23,7 @@
|
|||||||
"unity_config.h": "c",
|
"unity_config.h": "c",
|
||||||
"unity_internals.h": "c",
|
"unity_internals.h": "c",
|
||||||
"stdarg.h": "c",
|
"stdarg.h": "c",
|
||||||
"graph.h": "c"
|
"graph.h": "c",
|
||||||
|
"unicstl_config.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
16
README.md
16
README.md
@ -28,6 +28,22 @@
|
|||||||
| **heap** | |**堆** |
|
| **heap** | |**堆** |
|
||||||
| heap_init2 | 数组 | 最大堆/最小堆 |
|
| heap_init2 | 数组 | 最大堆/最小堆 |
|
||||||
|
|
||||||
|
## 特点
|
||||||
|
| 原理 | 说明 |
|
||||||
|
| --- | --- |
|
||||||
|
| 链表 | 有额外指针开销 |
|
||||||
|
| 动态数组 | 扩容时数据搬移代价较大 |
|
||||||
|
|
||||||
|
|
||||||
|
## 性能比较
|
||||||
|
|项目| 数组| 链表|
|
||||||
|
|---|---|---|
|
||||||
|
|查找| $O(1)$ | $O(n)$ |
|
||||||
|
|插入| $O(n)$ | $O(1)$ |
|
||||||
|
|删除| $O(n)$ | $O(1)$ |
|
||||||
|
|
||||||
|
**【A1】** 若链表的操作流程为,先查找元素再删除元素。那么时间复杂度确实是$O(n)$。但是链表的增删优势,在其他应用有体现。比如双向队列,插入和删除效率都为$O(1)$。
|
||||||
|
|
||||||
|
|
||||||
## 版本
|
## 版本
|
||||||
| 版本 | 说明 |
|
| 版本 | 说明 |
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
#ifndef _COMMON_H_
|
#ifndef _COMMON_H_
|
||||||
#define _COMMON_H_
|
#define _COMMON_H_
|
||||||
|
|
||||||
// #define NDEBUG 1
|
// #ifdef UNICSTL_CONFIG
|
||||||
|
#include "unicstl_config.h"
|
||||||
|
// #endif
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#ifndef _UNICSTL_H_
|
#ifndef _UNICSTL_H_
|
||||||
#define _UNICSTL_H_
|
#define _UNICSTL_H_
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
33
include/unicstl_config.h
Normal file
33
include/unicstl_config.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* @file unicstl_config.h
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2025-04-22
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2025
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef _UNICSTL_CONFIG_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief unicstl container
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define UNICSTL_LIST
|
||||||
|
#define UNICSTL_STACK
|
||||||
|
#define UNICSTL_QUEUE
|
||||||
|
#define UNICSTL_DEQUE
|
||||||
|
#define UNICSTL_TREE
|
||||||
|
#define UNICSTL_HEAP
|
||||||
|
#define UNICSTL_GRAPH
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief debug
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define NDEBUG
|
||||||
|
#define UNICSTL_DEBUG
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
@ -16,8 +16,8 @@ static void test_list_init2(void)
|
|||||||
// ------------------------------
|
// ------------------------------
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
TEST_ASSERT_FALSE(list_init2(NULL, sizeof(int), 1));
|
TEST_ASSERT_FALSE(list_init2(NULL, sizeof(int), 1));
|
||||||
TEST_ASSERT_FALSE(list_init2(list, 0, 1));
|
TEST_ASSERT_FALSE(list_init2(&list, 0, 1));
|
||||||
TEST_ASSERT_FALSE(list_init2(list, sizeof(int), 0));
|
TEST_ASSERT_FALSE(list_init2(&list, sizeof(int), 0));
|
||||||
#endif
|
#endif
|
||||||
TEST_ASSERT_TRUE(list_init2(&list, sizeof(int), 1));
|
TEST_ASSERT_TRUE(list_init2(&list, sizeof(int), 1));
|
||||||
list.destory(&list);
|
list.destory(&list);
|
||||||
|
Loading…
Reference in New Issue
Block a user