diff --git a/.gitignore b/.gitignore
index 2f75ee7..db05b25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
-# chm
-*.chm
+# cmake
+build/
# SI4
SIP.si4project/
diff --git a/CMakelists.txt b/CMakelists.txt
new file mode 100644
index 0000000..7531ffa
--- /dev/null
+++ b/CMakelists.txt
@@ -0,0 +1,24 @@
+
+# 0. cmake 最低版本号要求
+cmake_minimum_required(VERSION 3.8)
+
+# 0. 项目信息
+project(demo)
+
+# 0. 查找当前目录下的所有文件,并将名称保存在DIR_SRC中
+# aux_source_directory(. DIR_SRC)
+
+# 1. 添加头文件路径
+include_directories(include)
+
+# 1. 添加子目录
+add_subdirectory(src)
+add_subdirectory(test)
+
+# 2. 支持GDB
+set(CMAKE_BUILD_TYPE "Debug")
+set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
+set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
+
+# install
+set(CMAKE_INSTALL_PREFIX "./release")
diff --git a/datastruct.sln b/datastruct.sln
deleted file mode 100644
index c07e05c..0000000
--- a/datastruct.sln
+++ /dev/null
@@ -1,31 +0,0 @@
-锘
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.28307.757
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "datastruct", "datastruct\datastruct.vcxproj", "{3990515A-48AA-4CFF-9014-C35B11F02C87}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
- Release|x64 = Release|x64
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Debug|x64.ActiveCfg = Debug|x64
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Debug|x64.Build.0 = Debug|x64
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Debug|x86.ActiveCfg = Debug|Win32
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Debug|x86.Build.0 = Debug|Win32
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Release|x64.ActiveCfg = Release|x64
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Release|x64.Build.0 = Release|x64
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Release|x86.ActiveCfg = Release|Win32
- {3990515A-48AA-4CFF-9014-C35B11F02C87}.Release|x86.Build.0 = Release|Win32
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {65951581-EEEC-4CFD-AC52-2B52711979E5}
- EndGlobalSection
-EndGlobal
diff --git a/datastruct/datastruct.vcxproj b/datastruct/datastruct.vcxproj
deleted file mode 100644
index de9ae8a..0000000
--- a/datastruct/datastruct.vcxproj
+++ /dev/null
@@ -1,175 +0,0 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 15.0
- {3990515A-48AA-4CFF-9014-C35B11F02C87}
- Win32Proj
- datastruct
- 10.0
-
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
-
-
- true
-
-
- false
-
-
- false
-
-
-
- Level3
- Disabled
- true
- WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- true
- Console
-
-
-
-
- Level3
- Disabled
- true
- _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- true
- Console
-
-
-
-
- Level3
- MaxSpeed
- true
- true
- true
- WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- true
- true
- true
- Console
-
-
-
-
- Level3
- MaxSpeed
- true
- true
- true
- NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- true
- true
- true
- Console
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/datastruct/datastruct.vcxproj.filters b/datastruct/datastruct.vcxproj.filters
deleted file mode 100644
index 4b77ada..0000000
--- a/datastruct/datastruct.vcxproj.filters
+++ /dev/null
@@ -1,96 +0,0 @@
-锘
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;hm;inl;inc;ipp;xsd
-
-
- {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
- rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
-
-
- {03f28c38-31fa-4cef-97f5-67fbe3b4a2e2}
-
-
- {9b4f0950-addb-4047-9212-61b574e2b25d}
-
-
-
-
- 婧愭枃浠
-
-
- 婧愭枃浠
-
-
- 婧愭枃浠
-
-
- 婧愭枃浠
-
-
- 婧愭枃浠
-
-
- 婧愭枃浠
-
-
- 娴嬭瘯
-
-
- 娴嬭瘯
-
-
- 娴嬭瘯
-
-
- 娴嬭瘯
-
-
- 娴嬭瘯
-
-
- 婧愭枃浠
-
-
- 娴嬭瘯
-
-
-
-
- 澶存枃浠
-
-
- 澶存枃浠
-
-
- 澶存枃浠
-
-
- 澶存枃浠
-
-
- 澶存枃浠
-
-
- 绀轰緥
-
-
- 娴嬭瘯
-
-
- 澶存枃浠
-
-
- 澶存枃浠
-
-
- 澶存枃浠
-
-
-
\ No newline at end of file
diff --git a/datastruct/datastruct.vcxproj.user b/datastruct/datastruct.vcxproj.user
deleted file mode 100644
index be25078..0000000
--- a/datastruct/datastruct.vcxproj.user
+++ /dev/null
@@ -1,4 +0,0 @@
-锘
-
-
-
\ No newline at end of file
diff --git a/example/CMakelists.txt b/example/CMakelists.txt
new file mode 100644
index 0000000..be39de8
--- /dev/null
+++ b/example/CMakelists.txt
@@ -0,0 +1,4 @@
+
+aux_source_directory(. DIR_LIB_SRC)
+
+add_library(unicstl STATIC ${DIR_LIB_SRC})
diff --git a/datastruct/demo.h b/example/demo.h
similarity index 100%
rename from datastruct/demo.h
rename to example/demo.h
diff --git a/datastruct/common.h b/include/common.h
similarity index 100%
rename from datastruct/common.h
rename to include/common.h
diff --git a/datastruct/config.h b/include/config.h
similarity index 100%
rename from datastruct/config.h
rename to include/config.h
diff --git a/datastruct/deque.h b/include/deque.h
similarity index 95%
rename from datastruct/deque.h
rename to include/deque.h
index 5913d39..7e987a8 100644
--- a/datastruct/deque.h
+++ b/include/deque.h
@@ -2,7 +2,7 @@
#ifndef _DEQUE_H_
#define _DEQUE_H_
-#include "common.h"
+#include "unicstl.h"
struct _deque_node
{
@@ -48,7 +48,7 @@ struct _deque
// compare
int (*cmp)(void* obj, void* obj2);
- bool (*sort)(struct _list* self, uint8_t reserve);
+ bool (*sort)(struct _deque* self, uint8_t reserve);
// print
void (*print)(struct _deque* self);
diff --git a/datastruct/list.h b/include/list.h
similarity index 97%
rename from datastruct/list.h
rename to include/list.h
index 89885d7..6f6dabd 100644
--- a/datastruct/list.h
+++ b/include/list.h
@@ -1,9 +1,7 @@
#ifndef _LIST_H_
#define _LIST_H_
-#include "common.h"
-
-#ifdef LIST
+#include "unicstl.h"
struct _list
{
@@ -52,6 +50,4 @@ struct _list
bool list_init(struct _list* list, uint32_t obj_size);
-#endif
-
#endif // _LIST_H_
diff --git a/datastruct/queue.h b/include/queue.h
similarity index 100%
rename from datastruct/queue.h
rename to include/queue.h
diff --git a/datastruct/rbtree.h b/include/rbtree.h
similarity index 100%
rename from datastruct/rbtree.h
rename to include/rbtree.h
diff --git a/datastruct/stack.h b/include/stack.h
similarity index 100%
rename from datastruct/stack.h
rename to include/stack.h
diff --git a/datastruct/tree.h b/include/tree.h
similarity index 100%
rename from datastruct/tree.h
rename to include/tree.h
diff --git a/include/unicstl.h b/include/unicstl.h
new file mode 100644
index 0000000..e608dd7
--- /dev/null
+++ b/include/unicstl.h
@@ -0,0 +1,29 @@
+
+#ifndef _DEMO_H_
+#define _DEMO_H_
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#if RBTREE == 1
+#include "rbtree.h"
+ typedef prbtree_node_t stack_data_t;
+ typedef prbtree_node_t queue_data_t;
+
+ typedef int list_data_t;
+#elif AVLTREE == 1
+#include "tree.h"
+ typedef ptree_node_t stack_data_t;
+ typedef ptree_node_t queue_data_t;
+#else
+ typedef int stack_data_t;
+ typedef int queue_data_t;
+ typedef int list_data_t;
+#endif
+
+#endif // _DEMO_H_
+
diff --git a/mk.bat b/mk.bat
new file mode 100644
index 0000000..6c5aa87
--- /dev/null
+++ b/mk.bat
@@ -0,0 +1,7 @@
+@REM D:\Lang\cmake-3.27.5-windows-x86_64\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=D:\Software\mingw64\bin\gcc.exe -DCMAKE_CXX_COMPILER:FILEPATH=D:\Software\mingw64\bin\g++.exe -SF:/OpenDemo/1_vsc_cmake -Bf:/OpenDemo/1_vsc_cmake/build -G "MinGW Makefiles"
+@REM cmake -Bbuild -G "Visual Studio 17 2022"
+
+cmake -B build -G "MinGW Makefiles"
+
+make -C build
+make -C install
diff --git a/src/CMakelists.txt b/src/CMakelists.txt
new file mode 100644
index 0000000..868185c
--- /dev/null
+++ b/src/CMakelists.txt
@@ -0,0 +1,7 @@
+
+aux_source_directory(. LIB_SRC)
+
+add_library(unicstl STATIC ${LIB_SRC})
+
+# install
+install(TARGETS unicstl DESTINATION bin)
diff --git a/datastruct/deque.c b/src/deque.c
similarity index 100%
rename from datastruct/deque.c
rename to src/deque.c
diff --git a/datastruct/list.c b/src/list.c
similarity index 100%
rename from datastruct/list.c
rename to src/list.c
diff --git a/datastruct/queue.c b/src/queue.c
similarity index 100%
rename from datastruct/queue.c
rename to src/queue.c
diff --git a/datastruct/rbtree.c b/src/rbtree.c
similarity index 100%
rename from datastruct/rbtree.c
rename to src/rbtree.c
diff --git a/datastruct/stack.c b/src/stack.c
similarity index 100%
rename from datastruct/stack.c
rename to src/stack.c
diff --git a/datastruct/tree.c b/src/tree.c
similarity index 100%
rename from datastruct/tree.c
rename to src/tree.c
diff --git a/src/unicstl.c b/src/unicstl.c
new file mode 100644
index 0000000..ec5c781
--- /dev/null
+++ b/src/unicstl.c
@@ -0,0 +1,2 @@
+
+#include "unicstl.h"
diff --git a/test/CMakelists.txt b/test/CMakelists.txt
new file mode 100644
index 0000000..4e20d8b
--- /dev/null
+++ b/test/CMakelists.txt
@@ -0,0 +1,12 @@
+
+aux_source_directory(. DIR_TEST)
+
+include_directories(.)
+
+# generate target
+add_executable(${PROJECT_NAME} test.c)
+# link libary
+target_link_libraries(${PROJECT_NAME} unicstl)
+
+# install
+install(TARGETS ${PROJECT_NAME} DESTINATION bin)
diff --git a/datastruct/main.c b/test/test.c
similarity index 89%
rename from datastruct/main.c
rename to test/test.c
index fc51abe..4b39e50 100644
--- a/datastruct/main.c
+++ b/test/test.c
@@ -1,4 +1,4 @@
-#include "common.h"
+
#include "test.h"
int main()
diff --git a/datastruct/test.h b/test/test.h
similarity index 87%
rename from datastruct/test.h
rename to test/test.h
index c9d4f28..902ae04 100644
--- a/datastruct/test.h
+++ b/test/test.h
@@ -2,9 +2,6 @@
#ifndef _TEST_H_
#define _TEST_H_
-#include
-#include
-
#include "common.h"
// It is recommended to keep one at the same time
@@ -22,9 +19,6 @@
#endif
#endif
-
-#define SYSTEM_PAUSE() (system("pause"))
-
void stack_test(void);
void queue_test(void);
void list_test(void);
diff --git a/datastruct/deque_test.c b/test/test_deque.c
similarity index 100%
rename from datastruct/deque_test.c
rename to test/test_deque.c
diff --git a/datastruct/list_test.c b/test/test_list.c
similarity index 100%
rename from datastruct/list_test.c
rename to test/test_list.c
diff --git a/datastruct/queue_test.c b/test/test_queue.c
similarity index 100%
rename from datastruct/queue_test.c
rename to test/test_queue.c
diff --git a/datastruct/rbtree_test.c b/test/test_rbtree.c
similarity index 100%
rename from datastruct/rbtree_test.c
rename to test/test_rbtree.c
diff --git a/datastruct/stack_test.c b/test/test_stack.c
similarity index 100%
rename from datastruct/stack_test.c
rename to test/test_stack.c
diff --git a/datastruct/tree_test.c b/test/tree_test.c
similarity index 100%
rename from datastruct/tree_test.c
rename to test/tree_test.c