mirror of
https://gitee.com/apaki/unicstl.git
synced 2026-05-29 07:04:20 +08:00
- 将所有打印和比较函数的参数指针从 `void*` 修改为 `const void*`,增强类型安全 - 引入自定义断言宏 `unicstl_assert` 及其实现,替换标准 `assert` - 优化动态数组容量增长策略,新增 `unicstl_new_capacity` 函数 - 重构链表 接口:`push`/`pop` 重命名为 `push_back`/`pop_front`,新增 `push_front`/`pop_back`/`insert`/`remove`/`contains` 方法 - 移除链表结构体中未使用的 `_index_front` 和 `_index_back` 成员 - 在头文件中补充关键函数的时间复杂度注释
73 lines
1.2 KiB
C
73 lines
1.2 KiB
C
/**
|
|
* @file demo.c
|
|
* @author wenjf (Orig5826@163.com)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2024-08-27
|
|
*
|
|
* @copyright Copyright (c) 2024
|
|
*
|
|
*/
|
|
#include "demo.h"
|
|
|
|
void print_num(const void* obj)
|
|
{
|
|
printf("(%2d ) ", *(int*)obj);
|
|
}
|
|
|
|
int compare_num(const void *obj, const void *obj2)
|
|
{
|
|
int num1 = *(int*)obj;
|
|
int num2 = *(int*)obj2;
|
|
if(num1 == num2)
|
|
{
|
|
return 0;
|
|
}
|
|
return num1 > num2 ? 1 : -1;
|
|
}
|
|
|
|
void print_struct(const void* obj)
|
|
{
|
|
struct _student* student = (struct _student*)obj;
|
|
printf("(%4d:%-8s) ", student->id, student->name);
|
|
}
|
|
|
|
int compare_struct(const void *obj, const void *obj2)
|
|
{
|
|
struct _student num1 = *(struct _student*)obj;
|
|
struct _student num2 = *(struct _student*)obj2;
|
|
if(num1.id == num2.id)
|
|
{
|
|
return 0;
|
|
}
|
|
return num1.id > num2.id ? 1 : -1;
|
|
}
|
|
|
|
void print_char(const void* obj)
|
|
{
|
|
printf("(%2c ) ", *(char*)obj);
|
|
}
|
|
|
|
void print_str(const void* obj)
|
|
{
|
|
printf("(%s ) ", (char*)obj);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
printf("----- unicstl demo -----\n");
|
|
// while (1)
|
|
{
|
|
demo_queue();
|
|
demo_stack();
|
|
demo_list();
|
|
demo_deque();
|
|
demo_tree();
|
|
demo_heap();
|
|
demo_graph();
|
|
}
|
|
|
|
printf("----- unicstl ok -----\n");
|
|
return 0;
|
|
}
|