From 762bd76fed88ab27fac300ec4a5efb17ce0af1b8 Mon Sep 17 00:00:00 2001
From: caiyuzheng <290198252@qq.com>
Date: Mon, 14 Sep 2020 00:28:29 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E4=BA=86=E5=BE=88=E5=A4=9A=E6=97=A0?=
=?UTF-8?q?=E6=95=88=E7=9A=84=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 1 +
.idea/General.iml | 2 -
.idea/misc.xml | 9 --
.idea/modules.xml | 8 --
.idea/workspace.xml | 203 ---------------------------------------
CMakeLists.txt | 4 +-
general/src/utils.cpp | 47 ++++-----
test/src/heapsort/main.c | 91 +++++++++---------
8 files changed, 73 insertions(+), 292 deletions(-)
delete mode 100644 .idea/General.iml
delete mode 100644 .idea/misc.xml
delete mode 100644 .idea/modules.xml
delete mode 100644 .idea/workspace.xml
diff --git a/.gitignore b/.gitignore
index 33a3483..ec72bc9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ src/net/新建文本文档.txt
cmake-build-debug/
.idea/
build/
+.vs/
diff --git a/.idea/General.iml b/.idea/General.iml
deleted file mode 100644
index f08604b..0000000
--- a/.idea/General.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 4219e70..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 46db6ba..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
deleted file mode 100644
index 1e40e62..0000000
--- a/.idea/workspace.xml
+++ /dev/null
@@ -1,203 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1575817908178
-
-
- 1575817908178
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 89a1042..42f6108 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
-cmake_minimum_required(VERSION 3.11)
+cmake_minimum_required(VERSION 3.10)
project(generallib)
add_subdirectory(general)
-SET(SRC_SDK sdk_main.c test/src/heapsort/main.c)#生成动态库需要至少包含一个源文件
+SET(SRC_SDK sdk_main.c test/src/heapsort/main.c)
add_library(generallib STATIC $ ${SRC_SDK})
link_directories(general/third/lib)
set_target_properties(generallib PROPERTIES LINKER_LANGUAGE CXX)
diff --git a/general/src/utils.cpp b/general/src/utils.cpp
index 35c80d3..c065555 100644
--- a/general/src/utils.cpp
+++ b/general/src/utils.cpp
@@ -3,37 +3,40 @@
//
#include "utils.h"
-string itos(int x){
+string itos(int x)
+{
char buf[100] = {0};
- itoa(x,buf,10);
+ itoa(x, buf, 10);
return string(buf);
}
-inline ENV_SYS CurrentEnvSys(){
- #ifdef linux
- return ENV_LINUX
- #endif
- #ifdef _WINDOWS
- return ENV_WINDOWS
- #endif
- #ifdef _UNIX
- return ENV_UNIX
- #endif
- #ifdef _WIN32
- return ENV_WINDOWS
- #endif
+inline ENV_SYS CurrentEnvSys()
+{
+#ifdef linux
+ return ENV_LINUX;
+#endif
+#ifdef _WINDOWS
+ return ENV_WINDOWS;
+#endif
+#ifdef _UNIX
+ return ENV_UNIX;
+#endif
+#ifdef _WIN32
+ return ENV_WINDOWS;
+#endif
return ENV_NONE;
}
-inline ENV_COMPILER CurrentEnvCompiler(){
- #ifdef __GNUC__
+inline ENV_COMPILER CurrentEnvCompiler()
+{
+#ifdef __GNUC__
return GCC;
- #endif
- #ifdef _MSC_VER
+#endif
+#ifdef _MSC_VER
return CL;
- #endif
- #ifdef __clang__
+#endif
+#ifdef __clang__
return CLANG;
- #endif
+#endif
return UNKNOWN;
}
diff --git a/test/src/heapsort/main.c b/test/src/heapsort/main.c
index 7ca2687..1029c51 100644
--- a/test/src/heapsort/main.c
+++ b/test/src/heapsort/main.c
@@ -1,10 +1,10 @@
#include
#include
#include
-#define LENGTH(a) ( (sizeof(a)) / (sizeof(a[0])) )
-static int m_heap[30]; // 数据
-static int m_capacity=30; // 总的容量
-static int m_size=0; // 实际容量(初始化为0)
+#define LENGTH(a) ((sizeof(a)) / (sizeof(a[0])))
+static int m_heap[30]; // 数据
+static int m_capacity = 30; // 总的容量
+static int m_size = 0; // 实际容量(初始化为0)
/*
* 返回data在二叉堆中的索引
*
@@ -14,10 +14,10 @@ static int m_size=0; // 实际容量(初始化为0)
*/
int get_index(int data)
{
- int i=0;
+ int i = 0;
- for(i=0; i= m_heap[l])
- break; //调整结束
+ if (l < end && m_heap[l] < m_heap[l + 1])
+ l++; // 左右两孩子中选择较大者,即m_heap[l+1]
+ if (tmp >= m_heap[l])
+ break; //调整结束
else
{
m_heap[c] = m_heap[l];
c = l;
- l = 2*l + 1;
+ l = 2 * l + 1;
}
}
m_heap[c] = tmp;
@@ -64,15 +64,15 @@ int maxheap_remove(int data)
{
int index;
// 如果"堆"已空,则返回-1
- if(m_size == 0)
+ if (m_size == 0)
return -1;
// 获取data在数组中的索引
index = get_index(data);
- if (index==-1)
+ if (index == -1)
return -1;
- m_heap[index] = m_heap[--m_size]; // 用最后元素填补
- maxheap_filterdown(index, m_size-1); // 从index位置开始自上向下调整为最大堆
+ m_heap[index] = m_heap[--m_size]; // 用最后元素填补
+ maxheap_filterdown(index, m_size - 1); // 从index位置开始自上向下调整为最大堆
return 0;
}
/*
@@ -85,30 +85,28 @@ int maxheap_remove(int data)
*/
static void maxheap_filterup(int start)
{
- int c = start; // 当前节点(current)的位置
- int p = ( c- 1)/2; // 父(parent)结点的位置
- int tmp = m_heap[c]; // 当前节点(current)的大小
+ int c = start; // 当前节点(current)的位置
+ int p = (c - 1) / 2; // 父(parent)结点的位置
+ int tmp = m_heap[c]; // 当前节点(current)的大小
- while(c > 0)
+ while (c > 0)
{
// 父节点大于当前节点
- if(m_heap[p] >= tmp)
+ if (m_heap[p] >= tmp)
break;
else
-<<<<<<< Updated upstream
- { // 父节点小于当前节点,就调换位置,当前节点作为父节点,来源于一个抢位置的概念
-=======
- { // 父节点小于当前节点,就调换位置,当前节点的值变成父节点的值,父节点的值变成当前节点的值,
- // 并且父节点接着和父节点的父节点进行比较,如果还是比父节点的值大,再次把发当前节点的值
- //
->>>>>>> Stashed changes
- m_heap[c] = m_heap[p];
+ { // 父节点小于当前节点,就调换位置,当前节点作为父节点,来源于一个抢位置的概念
+ == == == =
+ { // 父节点小于当前节点,就调换位置,当前节点的值变成父节点的值,父节点的值变成当前节点的值,
+ // 并且父节点接着和父节点的父节点进行比较,如果还是比父节点的值大,再次把发当前节点的值
+ //
+ m_heap[c] = m_heap[p];
c = p;
- p = (p - 1)/2; // 再把当前节点和上一个父节点在比较大小
+ p = (p - 1) / 2; // 再把当前节点和上一个父节点在比较大小
}
}
// 找到合适的索引
- m_heap[c] = tmp; //最后把设置值
+ m_heap[c] = tmp; //最后把设置值
}
/*
* 将data插入到二叉堆中
@@ -120,12 +118,12 @@ static void maxheap_filterup(int start)
int maxheap_insert(int data)
{
// 如果"堆"已满,则返回
- if(m_size == m_capacity)
+ if (m_size == m_capacity)
return -1;
- m_heap[m_size] = data; // 将"数组"插在表尾
- maxheap_filterup(m_size); // 向上调整堆
- m_size++; // 堆的实际容量+1
+ m_heap[m_size] = data; // 将"数组"插在表尾
+ maxheap_filterup(m_size); // 向上调整堆
+ m_size++; // 堆的实际容量+1
return 0;
}
@@ -133,32 +131,33 @@ int maxheap_insert(int data)
void maxheap_print()
{
int i;
- for (i=0; i