写了双链表和动态数组头插法注释
This commit is contained in:
parent
a6bff78a29
commit
99e4c5219e
Binary file not shown.
Binary file not shown.
|
@ -89,6 +89,7 @@ int DArray_unshift(DArray *array, void *el)
|
|||
{
|
||||
int success_or_failure = 0;
|
||||
|
||||
// 如果空间不够,则动态调整数组大小
|
||||
if (ZED_MACRO_DArray_end(array) >= ZED_MACRO_DArray_max(array))
|
||||
{
|
||||
success_or_failure = DArray_expand(array);
|
||||
|
@ -96,15 +97,19 @@ int DArray_unshift(DArray *array, void *el)
|
|||
|
||||
if (array -> end > 0)
|
||||
{
|
||||
// 数组元素后移
|
||||
for (int i = array -> end; i > 0; --i)
|
||||
{
|
||||
array -> contents[i - 1] = array -> contents[i];
|
||||
}
|
||||
}
|
||||
|
||||
// 插入节点
|
||||
array -> contents[0] = el;
|
||||
// 节点数加一
|
||||
++(array -> end);
|
||||
|
||||
// 如果空间已满,则拓展数组空间
|
||||
if (ZED_MACRO_DArray_end(array) >= ZED_MACRO_DArray_max(array))
|
||||
{
|
||||
success_or_failure = DArray_expand(array);
|
||||
|
|
Binary file not shown.
|
@ -172,15 +172,21 @@ void List_unshift(List *list, char *value)
|
|||
|
||||
node -> value = value;
|
||||
|
||||
// 如果双链表为空,则直接插入节点
|
||||
if (NULL == list->first) {
|
||||
list->first = node;
|
||||
list->last = node;
|
||||
} else {
|
||||
}
|
||||
else // 否则在表头插入节点
|
||||
{
|
||||
// 设置待插入节点与原来的头节点的指针
|
||||
node->next = list->first;
|
||||
list->first->prev = node;
|
||||
// 将待插入节点设置为头节点
|
||||
list->first = node;
|
||||
}
|
||||
|
||||
// 节点数加一
|
||||
++(list->count);
|
||||
|
||||
error:
|
||||
|
|
Binary file not shown.
|
@ -12,6 +12,7 @@ DArray_contract ./src/lcthw/darray.c /^int DArray_contract(DArray *array)$/;" f
|
|||
DArray_create ./src/lcthw/darray.c /^DArray *DArray_create(size_t element_size, size_t initial_max)$/;" f
|
||||
DArray_destroy ./src/lcthw/darray.c /^void DArray_destroy(DArray *array)$/;" f
|
||||
DArray_expand ./src/lcthw/darray.c /^int DArray_expand(DArray *array)$/;" f
|
||||
DArray_free ./src/lcthw/darray.h 101;" d
|
||||
DArray_free ./src/lcthw/darray.h 80;" d
|
||||
DArray_get ./src/lcthw/darray.h /^static inline void *DArray_get(DArray *array, int i)$/;" f
|
||||
DArray_new ./src/lcthw/darray.h /^static inline void *DArray_new(DArray *array)$/;" f
|
||||
|
@ -19,8 +20,11 @@ DArray_pop ./src/lcthw/darray.c /^void *DArray_pop(DArray *array)$/;" f
|
|||
DArray_push ./src/lcthw/darray.c /^int DArray_push(DArray *array, void *el)$/;" f
|
||||
DArray_remove ./src/lcthw/darray.h /^static inline void *DArray_remove(DArray *array, int i)$/;" f
|
||||
DArray_resize ./src/lcthw/darray.c /^static inline int DArray_resize(DArray *array, size_t newsize)$/;" f file:
|
||||
DArray_resize ./src/lcthw/darray.h /^static inline int DArray_resize(DArray *array, size_t newsize)$/;" f
|
||||
DArray_set ./src/lcthw/darray.h /^static inline void DArray_set(DArray *array, int i, void *el)$/;" f
|
||||
DArray_unshift ./src/lcthw/darray.c /^int DArray_unshift(DArray *array, void *el)$/;" f
|
||||
DEFAULT_EXPAND_RATE ./src/lcthw/darray.h 37;" d
|
||||
DEFAULT_EXPAND_RATE ./src/lcthw/darray.h 39;" d
|
||||
List ./src/lcthw/list.h /^typedef struct List {$/;" s
|
||||
List ./src/lcthw/list.h /^} List;$/;" t typeref:struct:List
|
||||
ListNode ./src/lcthw/list.h /^typedef struct ListNode {$/;" s
|
||||
|
@ -71,10 +75,15 @@ ZED_MACRO_CHECK_DEBUG ./src/lcthw/dbg.h 35;" d
|
|||
ZED_MACRO_CHECK_MEM ./src/lcthw/dbg.h 32;" d
|
||||
ZED_MACRO_CLEAN_ERRNO ./src/lcthw/dbg.h 14;" d
|
||||
ZED_MACRO_DArray_count ./src/lcthw/darray.h 34;" d
|
||||
ZED_MACRO_DArray_count ./src/lcthw/darray.h 36;" d
|
||||
ZED_MACRO_DArray_end ./src/lcthw/darray.h 33;" d
|
||||
ZED_MACRO_DArray_end ./src/lcthw/darray.h 35;" d
|
||||
ZED_MACRO_DArray_first ./src/lcthw/darray.h 32;" d
|
||||
ZED_MACRO_DArray_first ./src/lcthw/darray.h 34;" d
|
||||
ZED_MACRO_DArray_last ./src/lcthw/darray.h 31;" d
|
||||
ZED_MACRO_DArray_last ./src/lcthw/darray.h 33;" d
|
||||
ZED_MACRO_DArray_max ./src/lcthw/darray.h 35;" d
|
||||
ZED_MACRO_DArray_max ./src/lcthw/darray.h 37;" d
|
||||
ZED_MACRO_DEBUG ./src/lcthw/dbg.h 11;" d
|
||||
ZED_MACRO_DEBUG ./src/lcthw/dbg.h 9;" d
|
||||
ZED_MACRO_LOG_ERR ./src/lcthw/dbg.h 17;" d
|
||||
|
@ -93,10 +102,13 @@ ZED_SENTINEL_MACRO ./src/lcthw/dbg.h 29;" d
|
|||
_DArray_h ./src/lcthw/darray.h 2;" d
|
||||
__dbg_h__ ./src/lcthw/dbg.h 2;" d
|
||||
_minunit_h ./tests/minunit.h 3;" d
|
||||
all_tests ./tests/darray_tests.c /^ZED_MACRO_RUN_TESTS(all_tests);$/;" v
|
||||
all_tests ./tests/darray_tests.c /^ZED_RUN_TESTS_MACRO(all_tests);$/;" v
|
||||
all_tests ./tests/darray_tests.c /^char *all_tests()$/;" f
|
||||
all_tests ./tests/list_algos_tests.c /^ZED_MACRO_RUN_TESTS(all_tests);$/;" v
|
||||
all_tests ./tests/list_algos_tests.c /^ZED_RUN_TESTS_MACRO(all_tests);$/;" v
|
||||
all_tests ./tests/list_algos_tests.c /^char *all_tests()$/;" f
|
||||
all_tests ./tests/list_tests.c /^ZED_MACRO_RUN_TESTS(all_tests);$/;" v
|
||||
all_tests ./tests/list_tests.c /^ZED_RUN_TESTS_MACRO(all_tests);$/;" v
|
||||
all_tests ./tests/list_tests.c /^char *all_tests()$/;" f
|
||||
array ./tests/darray_tests.c /^static DArray *array = NULL;$/;" v file:
|
||||
|
@ -133,8 +145,10 @@ test_push_copy ./tests/list_tests.c /^char *test_push_copy()$/;" f
|
|||
test_push_pop ./tests/darray_tests.c /^char *test_push_pop()$/;" f
|
||||
test_push_pop1 ./tests/list_tests.c /^char *test_push_pop1()$/;" f
|
||||
test_remove ./tests/darray_tests.c /^char *test_remove()$/;" f
|
||||
test_resize ./tests/darray_tests.c /^char *test_resize()$/;" f
|
||||
test_set ./tests/darray_tests.c /^char *test_set()$/;" f
|
||||
test_split ./tests/list_tests.c /^char *test_split()$/;" f
|
||||
test_unshift ./tests/darray_tests.c /^char *test_unshift()$/;" f
|
||||
test_unshift_remove_shift ./tests/list_tests.c /^char *test_unshift_remove_shift()$/;" f
|
||||
tests_run_globel ./tests/minunit.h /^int tests_run_globel = 0;$/;" v
|
||||
val1 ./tests/darray_tests.c /^static int *val1 = NULL;$/;" v file:
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -39,3 +39,44 @@ DEBUG tests/list_tests.c:272:
|
|||
----- test_merge
|
||||
DEBUG tests/list_tests.c:273:
|
||||
----- test_split
|
||||
DEBUG tests/darray_tests.c:201: ----- RUNNING: ./tests/darray_tests
|
||||
DEBUG tests/darray_tests.c:187:
|
||||
----- test_create
|
||||
DEBUG tests/darray_tests.c:188:
|
||||
----- test_new
|
||||
DEBUG tests/darray_tests.c:189:
|
||||
----- test_set
|
||||
DEBUG tests/darray_tests.c:190:
|
||||
----- test_get
|
||||
DEBUG tests/darray_tests.c:191:
|
||||
----- test_remove
|
||||
DEBUG tests/darray_tests.c:192:
|
||||
----- test_expand_contract
|
||||
DEBUG tests/darray_tests.c:193:
|
||||
----- test_unshift
|
||||
DEBUG tests/darray_tests.c:194:
|
||||
----- test_push_pop
|
||||
DEBUG tests/darray_tests.c:195:
|
||||
----- test_resize
|
||||
DEBUG tests/darray_tests.c:196:
|
||||
----- test_destroy
|
||||
DEBUG tests/list_algos_tests.c:221: ----- RUNNING: ./tests/list_algos_tests
|
||||
DEBUG tests/list_algos_tests.c:214:
|
||||
----- test_bubble_sort
|
||||
DEBUG tests/list_algos_tests.c:215:
|
||||
----- test_merge_sort
|
||||
DEBUG tests/list_algos_tests.c:216:
|
||||
----- test_insert
|
||||
DEBUG tests/list_tests.c:278: ----- RUNNING: ./tests/list_tests
|
||||
DEBUG tests/list_tests.c:268:
|
||||
----- test_create_destroy
|
||||
DEBUG tests/list_tests.c:269:
|
||||
----- test_push_pop1
|
||||
DEBUG tests/list_tests.c:270:
|
||||
----- test_unshift_remove_shift
|
||||
DEBUG tests/list_tests.c:271:
|
||||
----- test_push_copy
|
||||
DEBUG tests/list_tests.c:272:
|
||||
----- test_merge
|
||||
DEBUG tests/list_tests.c:273:
|
||||
----- test_split
|
||||
|
|
Loading…
Reference in New Issue