Skip to content

Commit

Permalink
完成了“堆排序”算法
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteen committed Jan 16, 2018
1 parent 58a5563 commit b16f402
Show file tree
Hide file tree
Showing 5 changed files with 340 additions and 0 deletions.
272 changes: 272 additions & 0 deletions 堆排序/堆排序.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 48;
objects = {

/* Begin PBXBuildFile section */
6AB2A57E200D8A5B00B9143B /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6AB2A57D200D8A5B00B9143B /* main.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
6AB2A578200D8A5B00B9143B /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
6AB2A57A200D8A5B00B9143B /* 堆排序 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "堆排序"; sourceTree = BUILT_PRODUCTS_DIR; };
6AB2A57D200D8A5B00B9143B /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
6AB2A577200D8A5B00B9143B /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
6AB2A571200D8A5B00B9143B = {
isa = PBXGroup;
children = (
6AB2A57C200D8A5B00B9143B /* 堆排序 */,
6AB2A57B200D8A5B00B9143B /* Products */,
);
sourceTree = "<group>";
};
6AB2A57B200D8A5B00B9143B /* Products */ = {
isa = PBXGroup;
children = (
6AB2A57A200D8A5B00B9143B /* 堆排序 */,
);
name = Products;
sourceTree = "<group>";
};
6AB2A57C200D8A5B00B9143B /* 堆排序 */ = {
isa = PBXGroup;
children = (
6AB2A57D200D8A5B00B9143B /* main.cpp */,
);
path = "堆排序";
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
6AB2A579200D8A5B00B9143B /* 堆排序 */ = {
isa = PBXNativeTarget;
buildConfigurationList = 6AB2A581200D8A5B00B9143B /* Build configuration list for PBXNativeTarget "堆排序" */;
buildPhases = (
6AB2A576200D8A5B00B9143B /* Sources */,
6AB2A577200D8A5B00B9143B /* Frameworks */,
6AB2A578200D8A5B00B9143B /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = "堆排序";
productName = "堆排序";
productReference = 6AB2A57A200D8A5B00B9143B /* 堆排序 */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
6AB2A572200D8A5B00B9143B /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = meituan;
TargetAttributes = {
6AB2A579200D8A5B00B9143B = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 6AB2A575200D8A5B00B9143B /* Build configuration list for PBXProject "堆排序" */;
compatibilityVersion = "Xcode 8.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = 6AB2A571200D8A5B00B9143B;
productRefGroup = 6AB2A57B200D8A5B00B9143B /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
6AB2A579200D8A5B00B9143B /* 堆排序 */,
);
};
/* End PBXProject section */

/* Begin PBXSourcesBuildPhase section */
6AB2A576200D8A5B00B9143B /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6AB2A57E200D8A5B00B9143B /* main.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
6AB2A57F200D8A5B00B9143B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
6AB2A580200D8A5B00B9143B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "-";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
};
name = Release;
};
6AB2A582200D8A5B00B9143B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
6AB2A583200D8A5B00B9143B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
6AB2A575200D8A5B00B9143B /* Build configuration list for PBXProject "堆排序" */ = {
isa = XCConfigurationList;
buildConfigurations = (
6AB2A57F200D8A5B00B9143B /* Debug */,
6AB2A580200D8A5B00B9143B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
6AB2A581200D8A5B00B9143B /* Build configuration list for PBXNativeTarget "堆排序" */ = {
isa = XCConfigurationList;
buildConfigurations = (
6AB2A582200D8A5B00B9143B /* Debug */,
6AB2A583200D8A5B00B9143B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 6AB2A572200D8A5B00B9143B /* Project object */;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>堆排序.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
47 changes: 47 additions & 0 deletions 堆排序/堆排序/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// main.cpp
// 堆排序
//
// Created by 郑祯 on 16/01/2018.
// Copyright © 2018 meituan. All rights reserved.
//

#include <iostream>

using namespace std;

void adjustMaxHeap(int *A, int start, int end) {
for (int current = start, left = start*2 + 1; left <= end; current = left, left = left * 2 + 1) {
if (left < end && A[left] < A[left + 1]) {
left++;
}
if (A[current] < A[left]) {
swap(A[current], A[left]);
} else {
break;
}
}
}

int* heapSort(int *A, int n) {
// 异常情况
if (n < 2 || A == NULL) {
return A;
}
// 调整为大顶堆
for (int i = n/2 - 1; i >= 0; i--) {
adjustMaxHeap(A, i, n - 1);
}
// 排序处理
for (int i = n - 1; i > 0;) {
swap(A[0], A[i]);
adjustMaxHeap(A, 0, --i);
}
return A;
}

int main(int argc, const char * argv[]) {
// insert code here...

return 0;
}

0 comments on commit b16f402

Please sign in to comment.