删了很多无效的代码

master
caiyuzheng 2020-09-14 00:28:29 +08:00
parent 92bc997726
commit 762bd76fed
8 changed files with 73 additions and 292 deletions

1
.gitignore vendored
View File

@ -4,3 +4,4 @@ src/net/新建文本文档.txt
cmake-build-debug/
.idea/
build/
.vs/

View File

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$/general">
<contentRoot DIR="$PROJECT_DIR$" />
</component>
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/General.iml" filepath="$PROJECT_DIR$/.idea/General.iml" />
</modules>
</component>
</project>

View File

@ -1,203 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="CMakeRunConfigurationManager" shouldGenerate="true" shouldDeleteObsolete="true">
<generated>
<config projectName="General" targetName="General" />
</generated>
</component>
<component name="CMakeSettings" AUTO_RELOAD="true">
<configurations>
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations>
</component>
<component name="ChangeListManager">
<list default="true" id="0facce0d-c642-4d80-b2fb-daf5f3e68dff" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/general/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/general/CMakeLists.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/general/src/pattern/cmd.hpp" beforeDir="false" afterPath="$PROJECT_DIR$/general/src/pattern/cmd.hpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ClangdSettings">
<option name="formatViaClangd" value="false" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="CMakeLists.txt" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="OCFindUsagesOptions" text="true" ivars="false" properties="true" derivedClasses="false" />
<component name="OCResolveContextSettings">
<option name="configuration" value="0-generallib" />
</component>
<component name="ProjectId" id="1UhntPy4Y6cJ81thpskTMk9Asng" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="cf.first.check.clang-format" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.tslint" value="project" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="D:\project\c++\generallib\general\src\ b-+" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\project\c++\generallib\src\encrypt" />
</key>
</component>
<component name="RunManager">
<configuration name="General" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="General" TARGET_NAME="General" CONFIG_NAME="Debug">
<method v="2">
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
</method>
</configuration>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="0facce0d-c642-4d80-b2fb-daf5f3e68dff" name="Default Changelist" comment="" />
<created>1575817908178</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1575817908178</updated>
<workItem from="1575817909426" duration="3242000" />
<workItem from="1575898054796" duration="4350000" />
<workItem from="1576304090241" duration="2459000" />
<workItem from="1576585606642" duration="7534000" />
<workItem from="1576913674335" duration="7707000" />
<workItem from="1576932562738" duration="10349000" />
<workItem from="1576983828513" duration="3804000" />
<workItem from="1577012242357" duration="1291000" />
<workItem from="1577695713801" duration="735000" />
<workItem from="1577715047417" duration="4424000" />
<workItem from="1577775991319" duration="2037000" />
<workItem from="1577933629796" duration="16000" />
<workItem from="1577933660908" duration="635000" />
<workItem from="1578153114620" duration="4070000" />
<workItem from="1578225965728" duration="1215000" />
<workItem from="1578280389789" duration="13088000" />
<workItem from="1578361985988" duration="3323000" />
<workItem from="1578460910091" duration="1945000" />
<workItem from="1578906765061" duration="6062000" />
<workItem from="1579014632931" duration="2670000" />
<workItem from="1580217628266" duration="1481000" />
<workItem from="1580474352803" duration="77000" />
<workItem from="1580647916171" duration="1188000" />
<workItem from="1580657914602" duration="599000" />
<workItem from="1581305036574" duration="7128000" />
<workItem from="1581558579086" duration="643000" />
<workItem from="1583501235151" duration="617000" />
<workItem from="1584890523991" duration="223000" />
<workItem from="1585674715896" duration="786000" />
<workItem from="1585735060761" duration="2165000" />
<workItem from="1585797079455" duration="1848000" />
<workItem from="1587146367315" duration="1596000" />
<workItem from="1587183781038" duration="13107000" />
<workItem from="1587266163206" duration="2365000" />
<workItem from="1587349363612" duration="16126000" />
<workItem from="1587473284944" duration="44000" />
<workItem from="1587473352763" duration="6395000" />
<workItem from="1587651371301" duration="5897000" />
<workItem from="1587713244566" duration="10654000" />
<workItem from="1588607501663" duration="599000" />
<workItem from="1588685364145" duration="2436000" />
<workItem from="1588731711427" duration="7486000" />
<workItem from="1588756178008" duration="9322000" />
<workItem from="1588780515188" duration="1174000" />
<workItem from="1588781713713" duration="809000" />
<workItem from="1588924890957" duration="190000" />
<workItem from="1588937000080" duration="6169000" />
<workItem from="1589005894180" duration="10282000" />
<workItem from="1589079851627" duration="4745000" />
<workItem from="1589096335715" duration="9622000" />
<workItem from="1589465397742" duration="4077000" />
<workItem from="1590041861831" duration="3306000" />
<workItem from="1590548574620" duration="180000" />
<workItem from="1590676222894" duration="3290000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="2" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="WindowStateProjectService">
<state x="361" y="110" key="#New_File_Extensions" timestamp="1589793685936">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="361" y="110" key="#New_File_Extensions/0.40.1536.824@0.40.1536.824" timestamp="1589793685936" />
<state x="651" y="314" width="409" height="388" key="#Notifications" timestamp="1588741195489">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="651" y="314" width="409" height="388" key="#Notifications/0.40.1536.824@0.40.1536.824" timestamp="1588741195489" />
<state x="223" y="107" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1588731831415">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="223" y="107" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.40.1536.824@0.40.1536.824" timestamp="1588731831415" />
<state x="549" y="206" key="FileChooserDialogImpl" timestamp="1588739069638">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="549" y="206" key="FileChooserDialogImpl/0.40.1536.824@0.40.1536.824" timestamp="1588739069638" />
<state x="270" y="96" key="SettingsEditor" timestamp="1588739395688">
<screen x="0" y="40" width="1536" height="824" />
</state>
<state x="270" y="96" key="SettingsEditor/0.40.1536.824@0.40.1536.824" timestamp="1588739395688" />
</component>
</project>

View File

@ -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 $<TARGET_OBJECTS:General> ${SRC_SDK})
link_directories(general/third/lib)
set_target_properties(generallib PROPERTIES LINKER_LANGUAGE CXX)

View File

@ -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;
}

View File

@ -1,10 +1,10 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#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_size; i++)
if (data==m_heap[i])
for (i = 0; i < m_size; i++)
if (data == m_heap[i])
return i;
return -1;
}
@ -32,22 +32,22 @@ int get_index(int data)
*/
static void maxheap_filterdown(int start, int end)
{
int c = start; // 当前(current)节点的位置
int l = 2*c + 1; // 左(left)孩子的位置
int tmp = m_heap[c]; // 当前(current)节点的大小
int c = start; // 当前(current)节点的位置
int l = 2 * c + 1; // 左(left)孩子的位置
int tmp = m_heap[c]; // 当前(current)节点的大小
while(l <= end)
while (l <= end)
{
// "l"是左孩子,"l+1"是右孩子
if(l < end && m_heap[l] < m_heap[l+1])
l++; // 左右两孩子中选择较大者即m_heap[l+1]
if(tmp >= 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<m_size; i++)
for (i = 0; i < m_size; i++)
printf("%d ", m_heap[i]);
}
void main()
{
int a[] = {10, 40, 30, 60, 90, 70, 20, 50, 80};
int i, len=LENGTH(a);
int i, len = LENGTH(a);
printf("== 堆排序: ");
for(i=0; i<len; i++)
for (i = 0; i < len; i++)
{
printf("%d \r\n", a[i]);
maxheap_insert(a[i]);
printf("round %d result:\r\n");
for(uint8_t z = 0;z < m_size;z++) {
printf("%d\r\n",m_heap[z]);
for (uint8_t z = 0; z < m_size; z++)
{
printf("%d\r\n", m_heap[z]);
}
printf("end\r\n");
}
printf("\n== 最 大 堆: ");
maxheap_print();
i=85;
i = 85;
maxheap_insert(i);
printf("\n== 添加元素: %d", i);
printf("\n== 最 大 堆: ");
maxheap_print();
i=90;
i = 90;
maxheap_remove(i);
printf("\n== 删除元素: %d", i);
printf("\n== 最 大 堆: ");