Merge branch 'develop' of https://github.com/saturneric/ZE-Standard-Libraries into develop
Fetch new.
This commit is contained in:
commit
733a304b62
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
################################################################################
|
||||
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
|
||||
################################################################################
|
||||
|
||||
/Debug
|
||||
/.vs/ZE-Standard-Libraries/v15
|
||||
/ZE-Standard-Libraries
|
||||
/ZE-Standard-Libraries.sln
|
307
ZE-Standard-Libraries.xcodeproj/project.pbxproj
Normal file
307
ZE-Standard-Libraries.xcodeproj/project.pbxproj
Normal file
@ -0,0 +1,307 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 50;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
9246995F20CE655900B4E894 /* tree.c in Sources */ = {isa = PBXBuildFile; fileRef = 9246995E20CE655900B4E894 /* tree.c */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
927993BB20CB87D6008CE3A9 /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
9246994F20CD000300B4E894 /* list.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = list.c; sourceTree = "<group>"; };
|
||||
9246995020CD000300B4E894 /* list_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list_expand.h; sourceTree = "<group>"; };
|
||||
9246995120CD000300B4E894 /* list.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = list.h; sourceTree = "<group>"; };
|
||||
9246995820CE52A700B4E894 /* stack.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack.h; sourceTree = "<group>"; };
|
||||
9246995920CE52A700B4E894 /* stack.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = stack.c; sourceTree = "<group>"; };
|
||||
9246995B20CE5C8900B4E894 /* stack_expand.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = stack_expand.h; sourceTree = "<group>"; };
|
||||
9246995D20CE655900B4E894 /* tree.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = tree.h; sourceTree = "<group>"; };
|
||||
9246995E20CE655900B4E894 /* tree.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = tree.c; sourceTree = "<group>"; };
|
||||
927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ZE-Standard-Libraries"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
927993BA20CB87D6008CE3A9 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
9246994E20CD000300B4E894 /* list */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9246994F20CD000300B4E894 /* list.c */,
|
||||
9246995020CD000300B4E894 /* list_expand.h */,
|
||||
9246995120CD000300B4E894 /* list.h */,
|
||||
);
|
||||
path = list;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9246995720CE507900B4E894 /* stack */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9246995820CE52A700B4E894 /* stack.h */,
|
||||
9246995920CE52A700B4E894 /* stack.c */,
|
||||
9246995B20CE5C8900B4E894 /* stack_expand.h */,
|
||||
);
|
||||
path = stack;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9246995C20CE654600B4E894 /* tree */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9246995D20CE655900B4E894 /* tree.h */,
|
||||
9246995E20CE655900B4E894 /* tree.c */,
|
||||
);
|
||||
path = tree;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
927993B420CB87D6008CE3A9 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9246995C20CE654600B4E894 /* tree */,
|
||||
9246995720CE507900B4E894 /* stack */,
|
||||
9246994E20CD000300B4E894 /* list */,
|
||||
927993BE20CB87D6008CE3A9 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
927993BE20CB87D6008CE3A9 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
927993BC20CB87D6008CE3A9 /* ZE-Standard-Libraries */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 927993C420CB87D6008CE3A9 /* Build configuration list for PBXNativeTarget "ZE-Standard-Libraries" */;
|
||||
buildPhases = (
|
||||
927993B920CB87D6008CE3A9 /* Sources */,
|
||||
927993BA20CB87D6008CE3A9 /* Frameworks */,
|
||||
927993BB20CB87D6008CE3A9 /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "ZE-Standard-Libraries";
|
||||
productName = "ZE-Standard-Libraries";
|
||||
productReference = 927993BD20CB87D6008CE3A9 /* ZE-Standard-Libraries */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
927993B520CB87D6008CE3A9 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 0940;
|
||||
ORGANIZATIONNAME = ZE;
|
||||
TargetAttributes = {
|
||||
927993BC20CB87D6008CE3A9 = {
|
||||
CreatedOnToolsVersion = 9.4;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 927993B820CB87D6008CE3A9 /* Build configuration list for PBXProject "ZE-Standard-Libraries" */;
|
||||
compatibilityVersion = "Xcode 9.3";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
);
|
||||
mainGroup = 927993B420CB87D6008CE3A9;
|
||||
productRefGroup = 927993BE20CB87D6008CE3A9 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
927993BC20CB87D6008CE3A9 /* ZE-Standard-Libraries */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
927993B920CB87D6008CE3A9 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
9246995F20CE655900B4E894 /* tree.c in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
927993C220CB87D6008CE3A9 /* 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_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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;
|
||||
};
|
||||
927993C320CB87D6008CE3A9 /* 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_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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;
|
||||
};
|
||||
927993C520CB87D6008CE3A9 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
927993C620CB87D6008CE3A9 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
927993B820CB87D6008CE3A9 /* Build configuration list for PBXProject "ZE-Standard-Libraries" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
927993C220CB87D6008CE3A9 /* Debug */,
|
||||
927993C320CB87D6008CE3A9 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
927993C420CB87D6008CE3A9 /* Build configuration list for PBXNativeTarget "ZE-Standard-Libraries" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
927993C520CB87D6008CE3A9 /* Debug */,
|
||||
927993C620CB87D6008CE3A9 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 927993B520CB87D6008CE3A9 /* Project object */;
|
||||
}
|
7
ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
7
ZE-Standard-Libraries.xcodeproj/project.xcworkspace/contents.xcworkspacedata
generated
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
@ -0,0 +1,8 @@
|
||||
<?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>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<VariablesViewState
|
||||
version = "1.0">
|
||||
<ContextStates>
|
||||
<ContextState
|
||||
contextName = "init_node:list.h">
|
||||
<PersistentStrings>
|
||||
<PersistentString
|
||||
value = "list_list">
|
||||
</PersistentString>
|
||||
</PersistentStrings>
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "releaseNULLList:list.h">
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "insertInTail:list.h">
|
||||
<PersistentStrings>
|
||||
<PersistentString
|
||||
value = "node_list">
|
||||
</PersistentString>
|
||||
<PersistentString
|
||||
value = "list_list">
|
||||
</PersistentString>
|
||||
</PersistentStrings>
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "releaseMalloc:list.h">
|
||||
</ContextState>
|
||||
<ContextState
|
||||
contextName = "init_list:list.h">
|
||||
</ContextState>
|
||||
</ContextStates>
|
||||
</VariablesViewState>
|
@ -0,0 +1,151 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Bucket
|
||||
type = "1"
|
||||
version = "2.0">
|
||||
<Breakpoints>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.c"
|
||||
timestampString = "550223770.817897"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "30"
|
||||
endingLineNumber = "30"
|
||||
landmarkName = "main"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.h"
|
||||
timestampString = "550223770.8183891"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "88"
|
||||
endingLineNumber = "88"
|
||||
landmarkName = "releaseSingleList(List *p_list)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.h"
|
||||
timestampString = "550223770.819275"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "161"
|
||||
endingLineNumber = "161"
|
||||
landmarkName = "init_list(void)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.h"
|
||||
timestampString = "550223770.81986"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "165"
|
||||
endingLineNumber = "165"
|
||||
landmarkName = "init_list(void)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.c"
|
||||
timestampString = "550223770.820323"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "20"
|
||||
endingLineNumber = "20"
|
||||
landmarkName = "main"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.c"
|
||||
timestampString = "550223770.8204269"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "31"
|
||||
endingLineNumber = "31"
|
||||
landmarkName = "main"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.c"
|
||||
timestampString = "550223770.820511"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "14"
|
||||
endingLineNumber = "14"
|
||||
landmarkName = "main"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.h"
|
||||
timestampString = "550223770.820591"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "189"
|
||||
endingLineNumber = "189"
|
||||
landmarkName = "getId(void)"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "ZE-Standard-Libraries/list/list.c"
|
||||
timestampString = "550223770.820963"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "19"
|
||||
endingLineNumber = "19"
|
||||
landmarkName = "main"
|
||||
landmarkType = "9">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
@ -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>ZE-Standard-Libraries.xcscheme</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
1
graph/graph.c
Normal file
1
graph/graph.c
Normal file
@ -0,0 +1 @@
|
||||
#include "graph.h"
|
24
graph/graph.h
Normal file
24
graph/graph.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef GRAPH_H
|
||||
#define GRAPH_H
|
||||
|
||||
#include "../list/list_expand.h"
|
||||
|
||||
typedef struct GNode{
|
||||
unsigned long long id;
|
||||
void *value;
|
||||
List *routes;
|
||||
int if_setValue;
|
||||
}GNode;
|
||||
|
||||
typedef struct route{
|
||||
unsigned long long id;
|
||||
double distance;
|
||||
int if_setValue;
|
||||
GNode from, to;
|
||||
}Route;
|
||||
|
||||
GNode *initGNode(void);
|
||||
Route *initRoute(void);
|
||||
|
||||
|
||||
#endif
|
BIN
list/list.c
BIN
list/list.c
Binary file not shown.
BIN
list/list.h
BIN
list/list.h
Binary file not shown.
351
list/list_expand.c
Normal file
351
list/list_expand.c
Normal file
@ -0,0 +1,351 @@
|
||||
#include "list_expand.h"
|
||||
|
||||
Node *nodeWithInt(int m_int) {
|
||||
Node *p_node;
|
||||
int *p_int = (int *)malloc(sizeof(int));
|
||||
*p_int = m_int;
|
||||
p_node = initNode();
|
||||
initMallocValueForNode(p_node, "int", (void *)p_int);
|
||||
return p_node;
|
||||
}
|
||||
|
||||
Node *nodeWithDouble(double m_double) {
|
||||
Node *p_node;
|
||||
double *p_double = (double *)malloc(sizeof(double));
|
||||
*p_double = m_double;
|
||||
p_node = initNode();
|
||||
initMallocValueForNode(p_node, "double", (void *)p_double);
|
||||
return p_node;
|
||||
}
|
||||
|
||||
Node *nodeWithString(const char *m_string) {
|
||||
Node *p_node;
|
||||
char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1));
|
||||
strcpy_s(p_string, sizeof(p_string), m_string);
|
||||
p_node = initNode();
|
||||
initMallocValueForNode(p_node, "string", (void *)p_string);
|
||||
return p_node;
|
||||
}
|
||||
|
||||
Node *nodeWithPointer(void *m_pointer) {
|
||||
Node *p_node = initNode();
|
||||
initMallocValueForNode(p_node, "pointer", m_pointer);
|
||||
return p_node;
|
||||
}
|
||||
|
||||
Node *nodeWithComplex(void) {
|
||||
Node *p_node = initNode();
|
||||
p_node->type = "list";
|
||||
p_node->value = initList();
|
||||
p_node->if_malloc = 1;
|
||||
return p_node;
|
||||
}
|
||||
|
||||
Node *findByIndexForNode(List *p_list, unsigned long long m_index) {
|
||||
Node *p_node = p_list->head;
|
||||
unsigned long long i;
|
||||
for (i = 0; i < m_index; i++) {
|
||||
p_node = p_node->next;
|
||||
}
|
||||
return p_node;
|
||||
}
|
||||
|
||||
int listThrough(List *p_list, int(*p_func)(const char *, void *)) {
|
||||
Node *p_node = p_list->head;
|
||||
while (p_node != NULL) {
|
||||
if (p_node->if_malloc == 1) {
|
||||
int m_return = (*p_func)(p_node->type, p_node->value);
|
||||
if (m_return == -1) break;
|
||||
else if (m_return == 1) {
|
||||
p_node = p_node->last;
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
p_node = p_node->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getByIntForNode(Node *p_node) {
|
||||
if (!strcmp(p_node->type, "int")) return *(int *)(p_node->value);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
char *getByStringForNode(Node *p_node) {
|
||||
if (!strcmp(p_node->type, "string")) return (char *)(p_node->value);
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
double getByDoubleForNode(Node *p_node) {
|
||||
if (!strcmp(p_node->type, "double")) return *(double *)(p_node->value);
|
||||
else return -1;
|
||||
}
|
||||
|
||||
void *getByPointerForNode(Node *p_node) {
|
||||
if (!strcmp(p_node->type, "pointer")) return (void *)(p_node->value);
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
void printListInfo(List *p_list, int priority) {
|
||||
int i = 0;
|
||||
Node *p_node;
|
||||
for (i = 0; i < priority; i++) printf(" ");
|
||||
printf("###LIST(location:%p, id:%llu){\n", p_list, p_list->id);
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("HEAD->%p / Tail->%p / Length:%llu\n", p_list->head, p_list->tail, p_list->length);
|
||||
p_node = p_list->head;
|
||||
while (p_node != NULL) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("%d.... \n", i);
|
||||
printNodeInfo(p_node, priority + 1);
|
||||
p_node = p_node->next;
|
||||
i++;
|
||||
}
|
||||
for (i = 0; i < priority; i++) printf(" ");
|
||||
printf("}\n");
|
||||
|
||||
}
|
||||
|
||||
void printList(List *p_list) {
|
||||
int if_nearLast = 0;
|
||||
Node *p_node = p_list->head;
|
||||
printf("[");
|
||||
while (p_node != NULL) {
|
||||
if (!if_nearLast && p_node->next == NULL) if_nearLast = 1;
|
||||
if (!strcmp(p_node->type, "int")) {
|
||||
printf("%d", *(int *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "double")) {
|
||||
printf("%a", *(double *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "string")) {
|
||||
printf("%s", (char *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "pointer")) {
|
||||
printf("%p", (char *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "list")) {
|
||||
printList((List *)p_node->value);
|
||||
}
|
||||
if (!if_nearLast) {
|
||||
printf(", ");
|
||||
}
|
||||
p_node = p_node->next;
|
||||
}
|
||||
printf("]");
|
||||
}
|
||||
|
||||
void printNodeInfo(Node *p_node, int priority) {
|
||||
int i;
|
||||
for (i = 0; i < priority; i++) printf(" ");
|
||||
printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id);
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc);
|
||||
if (!strcmp(p_node->type, "int")) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("VALUE(int):%d\n", *(int *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "double")) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("VALUE(double):%a\n", *(double *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "string")) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("VALUE(string):%s\n", (char *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "pointer")) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("VALUE(pointer):%s\n", (char *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "list")) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("VALUE(List):\n");
|
||||
printListInfo((List *)p_node->value, priority + 2);
|
||||
}
|
||||
for (i = 0; i < priority; i++) printf(" ");
|
||||
printf("}\n");
|
||||
}
|
||||
|
||||
void printNode(Node *p_node) {
|
||||
int i;
|
||||
printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id);
|
||||
printf(" ");
|
||||
printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last, p_node->if_malloc);
|
||||
for (i = 0; i < 1; i++) printf(" ");
|
||||
printf("ifMalloc: ");
|
||||
if (p_node->if_malloc) {
|
||||
printf("YES\n");
|
||||
for (i = 0; i < 1; i++) printf(" ");
|
||||
printf("Value(type: %s): ", p_node->type);
|
||||
if (!strcmp(p_node->type, "int")) {
|
||||
printf("%d", *(int *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "double")) {
|
||||
printf("%a\n", *(double *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "string")) {
|
||||
printf("%s\n", (char *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "pointer")) {
|
||||
printf("%s\n", (char *)(p_node->value));
|
||||
}
|
||||
else if (!strcmp(p_node->type, "list")) {
|
||||
printList((List *)p_node->value);
|
||||
}
|
||||
}
|
||||
else printf("NO\n");
|
||||
|
||||
printf("}\n");
|
||||
}
|
||||
|
||||
|
||||
Node *findByIntForNode(List *p_list, int target) {
|
||||
Node *t_node;
|
||||
int *p_target = (int *)malloc(sizeof(int));
|
||||
*p_target = target;
|
||||
t_node = findByValue(p_list, "int", p_target);
|
||||
free(p_target);
|
||||
return t_node;
|
||||
}
|
||||
|
||||
Node *findByDoubleForNode(List *p_list, double target) {
|
||||
Node *t_node;
|
||||
double *p_target = (double *)malloc(sizeof(double));
|
||||
*p_target = target;
|
||||
t_node = findByValue(p_list, "double", p_target);
|
||||
free(p_target);
|
||||
return t_node;
|
||||
}
|
||||
|
||||
Node *findByStringForNode(List *p_list, char *target) {
|
||||
Node *t_node;
|
||||
char *p_temp = (char *)malloc(sizeof(char)*(strlen(target) + 1));
|
||||
strcpy_s(p_temp, sizeof(p_temp), target);
|
||||
t_node = findByValue(p_list, "string", p_temp);
|
||||
free(p_temp);
|
||||
return t_node;
|
||||
}
|
||||
|
||||
Node *findByPointerForNode(List *p_list, void *target) {
|
||||
Node *t_node = findByValue(p_list, "pointer", target);
|
||||
return t_node;
|
||||
}
|
||||
|
||||
int addValueForComplex(Node * p_node, char *type, void *value) {
|
||||
List *c_list;
|
||||
Node *c_node;
|
||||
if (!strcmp(p_node->type, "list")) {
|
||||
c_list = (List *)p_node->value;
|
||||
c_node = initNode();
|
||||
initMallocValueForNode(c_node, type, value);
|
||||
insertInTail(c_list, c_node);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int addIntForComplex(Node *p_node, int temp) {
|
||||
if (!strcmp(p_node->type, "list")) {
|
||||
int *p_temp = (int *)malloc(sizeof(int));
|
||||
*p_temp = temp;
|
||||
addValueForComplex(p_node, "int", p_temp);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int addDoubleForComplex(Node *p_node, double temp) {
|
||||
if (!strcmp(p_node->type, "list")) {
|
||||
double *p_temp = (double *)malloc(sizeof(double));
|
||||
*p_temp = temp;
|
||||
addValueForComplex(p_node, "double", p_temp);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int addStringForComplex(Node *p_node, char *temp) {
|
||||
if (!strcmp(p_node->type, "list")) {
|
||||
char *p_temp = (char *)malloc(sizeof(strlen(temp) + 1));
|
||||
strcpy_s(p_temp, sizeof(p_temp), temp);
|
||||
addValueForComplex(p_node, "string", p_temp);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int addPointerForComplex(Node *p_node, void *temp) {
|
||||
if (!strcmp(p_node->type, "list")) {
|
||||
addValueForComplex(p_node, "pointer", temp);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
List *m_findByInt(List* p_list, int temp) {
|
||||
int *p_temp = (int *)malloc(sizeof(int));
|
||||
List *t_list;
|
||||
*p_temp = temp;
|
||||
t_list = mply_findByValue(p_list, "int", (void *)p_temp);
|
||||
free(p_temp);
|
||||
return t_list;
|
||||
}
|
||||
|
||||
List *m_findByDouble(List* p_list, double temp) {
|
||||
List *t_list;
|
||||
double *p_temp = (double *)malloc(sizeof(double));
|
||||
*p_temp = temp;
|
||||
t_list = mply_findByValue(p_list, "double", (void *)p_temp);
|
||||
free(p_temp);
|
||||
return t_list;
|
||||
}
|
||||
|
||||
List *m_findByString(List* p_list, char *temp) {
|
||||
List *t_list;
|
||||
char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1));
|
||||
strcpy_s(p_temp, sizeof(p_temp), temp);
|
||||
t_list = mply_findByValue(p_list, "string", (void *)p_temp);
|
||||
free(p_temp);
|
||||
return t_list;
|
||||
}
|
||||
|
||||
List *m_findByPointer(List* p_list, void *temp) {
|
||||
List *t_list = mply_findByValue(p_list, "double", (void *)temp);
|
||||
return t_list;
|
||||
}
|
||||
|
||||
unsigned long long getIndexByNode(List *p_list, Node *p_node) {
|
||||
Node *t_node = p_list->head;
|
||||
unsigned long long index = 0;
|
||||
while (t_node != NULL) {
|
||||
if (p_node->id == t_node->id) return index;
|
||||
index++;
|
||||
t_node = t_node->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
List *m_findByIntForNode(List* p_list, int temp) {
|
||||
int *p_temp = (int *)malloc(sizeof(int));
|
||||
*p_temp = temp;
|
||||
return mply_findByValue(p_list, "int", (void *)p_temp);
|
||||
}
|
||||
|
||||
List *m_findByDoubleForNode(List* p_list, double temp) {
|
||||
double *p_temp = (double *)malloc(sizeof(double));
|
||||
*p_temp = temp;
|
||||
return mply_findByValue(p_list, "double", (void *)p_temp);
|
||||
}
|
||||
|
||||
List *m_findByStringForNode(List* p_list, char *temp) {
|
||||
char *p_temp = (char *)malloc(sizeof(char) * (strlen(temp) + 1));
|
||||
strcpy_s(p_temp, sizeof(p_temp), temp);
|
||||
return mply_findByValue(p_list, "string", (void *)p_temp);
|
||||
}
|
||||
|
||||
List *m_findByPointerForNode(List* p_list, void *temp) {
|
||||
return mply_findByValue(p_list, "pointer", (void *)temp);
|
||||
}
|
Binary file not shown.
BIN
stack/stack.c
BIN
stack/stack.c
Binary file not shown.
BIN
stack/stack.h
BIN
stack/stack.h
Binary file not shown.
51
stack/stack_expand.c
Normal file
51
stack/stack_expand.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include "stack_expand.h"
|
||||
|
||||
SNode *snodeWithInt(int temp) {
|
||||
SNode *p_snode = initSNode();
|
||||
int *p_temp = (int *)malloc(sizeof(int));
|
||||
*p_temp = temp;
|
||||
initMallocValueForSNode(p_snode, "int", p_temp);
|
||||
return p_snode;
|
||||
}
|
||||
|
||||
SNode *snodeWithDouble(double temp) {
|
||||
SNode *p_snode = initSNode();
|
||||
double *p_temp = (double *)malloc(sizeof(double));
|
||||
*p_temp = temp;
|
||||
initMallocValueForSNode(p_snode, "double", p_temp);
|
||||
return p_snode;
|
||||
}
|
||||
|
||||
SNode *snodeWithString(char *temp) {
|
||||
SNode *p_snode = initSNode();
|
||||
char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1));
|
||||
strcpy_s(p_temp, strlen(p_temp), temp);
|
||||
initMallocValueForSNode(p_snode, "string", p_temp);
|
||||
return p_snode;
|
||||
}
|
||||
|
||||
SNode *snodeWithPointer(void *temp) {
|
||||
SNode *p_snode = initSNode();
|
||||
initMallocValueForSNode(p_snode, "pointer", temp);
|
||||
return p_snode;
|
||||
}
|
||||
|
||||
int getValueByIntForSNode(SNode *p_snode) {
|
||||
if (!strcmp(p_snode->type, "int")) return *(int *)p_snode->value;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
double getValueByDoubleForSNode(SNode *p_snode) {
|
||||
if (!strcmp(p_snode->type, "double")) return *(double *)p_snode->value;
|
||||
else return -1;
|
||||
}
|
||||
|
||||
char *getValueByStringForSNode(SNode *p_snode) {
|
||||
if (!strcmp(p_snode->type, "int")) return (char *)p_snode->value;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
void *getValueByPointerForSNode(SNode *p_snode) {
|
||||
if (!strcmp(p_snode->type, "int")) return (void *)p_snode->value;
|
||||
else return NULL;
|
||||
}
|
Binary file not shown.
90
test.c
Normal file
90
test.c
Normal file
@ -0,0 +1,90 @@
|
||||
#include "test.h"
|
||||
|
||||
|
||||
int list(void) {
|
||||
int i;
|
||||
List *t_list, *m_list;;
|
||||
init_rand();
|
||||
safeModeForNode(1);
|
||||
t_list = initList();
|
||||
|
||||
/*for(int i = 0; i < 9; i++){
|
||||
Node *t_node = initNode();
|
||||
int *t_i = (int *)malloc(sizeof(int));
|
||||
*t_i = i;
|
||||
initMallocValue(t_node,"int",(void *)t_i);
|
||||
insertInTail(t_list,t_node);
|
||||
}*/
|
||||
|
||||
/*Node *t_node = initNode();
|
||||
insertInTail(t_list,t_node);
|
||||
initMalllocValue(t_node,(void *)"there");*/
|
||||
|
||||
for (i = 0; i < 12; i++) {
|
||||
insertInHead(t_list, nodeWithInt(i));
|
||||
insertInTail(t_list, nodeWithInt(i));
|
||||
}
|
||||
|
||||
|
||||
|
||||
printListInfo(t_list, 0);
|
||||
printList(t_list);
|
||||
|
||||
m_list = m_findByIntForNode(t_list, 5);
|
||||
printList(m_list);
|
||||
printf("\n");
|
||||
|
||||
releaseAllForNode();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _useTreeThroughDown(TNode *p_tnode, unsigned long long height) {
|
||||
printTNode(p_tnode,0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int tree(void) {
|
||||
TNode *t_tnode, *cr_tnode, *cl_tnode;
|
||||
Tree *t_tree;
|
||||
TNode *gs_tnode;
|
||||
safeModeForTree(1);
|
||||
t_tree = initTree();
|
||||
t_tnode = tnodeWithInt(1);
|
||||
cr_tnode = tnodeWithInt(3);
|
||||
cl_tnode = tnodeWithInt(2);
|
||||
addChildInRight(t_tnode, cl_tnode);
|
||||
addChildInRight(t_tnode, cr_tnode);
|
||||
addChildInRight(cl_tnode, tnodeWithInt(4));
|
||||
gs_tnode = tnodeWithInt(5);
|
||||
addChildInRight(cl_tnode,gs_tnode);
|
||||
addChildInRight(cr_tnode, tnodeWithInt(6));
|
||||
addChildInRight(cr_tnode, tnodeWithInt(7));
|
||||
addChildInRight(gs_tnode, tnodeWithInt(8));
|
||||
setRoot(t_tree, t_tnode);
|
||||
TreeThroughUp(t_tree, _useTreeThroughDown);
|
||||
//printTNodeWithFamily(t_tnode, 0);
|
||||
releaseAllForTree();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stack(void) {
|
||||
int i;
|
||||
Stack *t_stack = initStack();
|
||||
for (i = 0; i < 10; i++) {
|
||||
pushStack(t_stack, snodeWithInt(i));
|
||||
}
|
||||
for (i = 0; i < 10; i++) {
|
||||
printf("%d", getValueByIntForSNode(popStack(t_stack)));
|
||||
}
|
||||
releaseStack(t_stack);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
tree();
|
||||
getchar();
|
||||
return 0;
|
||||
}
|
16
test.h
Normal file
16
test.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef TEST_H
|
||||
#define TEST_H
|
||||
|
||||
#include<stdio.h>
|
||||
|
||||
#include "list/list_expand.h"
|
||||
#include "stack/stack_expand.h"
|
||||
#include "tree/tree.h"
|
||||
#include "tree/tree_expand.h"
|
||||
|
||||
int stack(void);
|
||||
int list(void);
|
||||
int tree(void);
|
||||
|
||||
#endif // TEST_H
|
||||
|
471
tree/tree.c
471
tree/tree.c
@ -1,9 +1,462 @@
|
||||
//
|
||||
// tree.c
|
||||
// ZE-Standard-Libraries
|
||||
//
|
||||
// Created by 胡一兵 on 2018/6/11.
|
||||
// Copyright © 2018年 ZE. All rights reserved.
|
||||
//
|
||||
|
||||
#include "tree.h"
|
||||
#include"tree.h"
|
||||
|
||||
unsigned long long target_id = 0;
|
||||
TNode *target_value_id = NULL;
|
||||
int if_safeModeForTree = 0;
|
||||
|
||||
int safeModeForTree(int ifon) {
|
||||
if (ifon == 1) {
|
||||
if (tnode_list == NULL && tree_list == NULL) {
|
||||
tnode_list = (List *)malloc(sizeof(List));
|
||||
tree_list = (List *)malloc(sizeof(List));
|
||||
|
||||
tree_list->head = NULL;
|
||||
tree_list->length = 0;
|
||||
tree_list->tail = NULL;
|
||||
|
||||
tnode_list->head = NULL;
|
||||
tnode_list->length = 0;
|
||||
tnode_list->tail = NULL;
|
||||
|
||||
if_safeModeForTree = 1;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return ifon;
|
||||
}
|
||||
|
||||
TNode *initTNode(void) {
|
||||
Node *s_node;
|
||||
TNode *p_tnode = (TNode *)malloc(sizeof(TNode));
|
||||
p_tnode->id = getId();
|
||||
p_tnode->child_num = 0;
|
||||
p_tnode->father = NULL;
|
||||
p_tnode->if_malloc = 0;
|
||||
p_tnode->value = NULL;
|
||||
p_tnode->type = NULL;
|
||||
p_tnode->home = initList();
|
||||
p_tnode->room = NULL;
|
||||
if (if_safeModeForTree) {
|
||||
if (if_safeModeForNode) {
|
||||
if_safeModeForNode = 0;
|
||||
s_node = initNode();
|
||||
initMallocValueForNode(s_node, "pointer", (void *)p_tnode);
|
||||
insertInTail(tnode_list, s_node);
|
||||
if_safeModeForNode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
s_node = initNode();
|
||||
initMallocValueForNode(s_node, "pointer", (void *)p_tnode);
|
||||
insertInTail(tnode_list, s_node);
|
||||
}
|
||||
}
|
||||
return p_tnode;
|
||||
}
|
||||
|
||||
Tree *initTree(void) {
|
||||
Node *s_node;
|
||||
Tree *p_tree = (Tree *)malloc(sizeof(Tree));
|
||||
p_tree->id = getId();
|
||||
p_tree->root = NULL;
|
||||
if (if_safeModeForTree) {
|
||||
if (if_safeModeForNode) {
|
||||
if_safeModeForNode = 0;
|
||||
s_node = initNode();
|
||||
initMallocValueForNode(s_node, "pointer", (void *)p_tree);
|
||||
if_safeModeForNode = 1;
|
||||
insertInTail(tree_list, s_node);
|
||||
}
|
||||
else
|
||||
{
|
||||
s_node = initNode();
|
||||
initMallocValueForNode(s_node, "pointer", (void *)p_tree);
|
||||
insertInTail(tree_list, s_node);
|
||||
}
|
||||
}
|
||||
return p_tree;
|
||||
}
|
||||
|
||||
int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value) {
|
||||
p_tnode->type = type;
|
||||
p_tnode->value = value;
|
||||
p_tnode->if_malloc = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int addChildInLeft(TNode *f_tnode, TNode *c_tnode) {
|
||||
Node *p_node = initNode();
|
||||
initMallocValueForNode(p_node, "pointer", c_tnode);
|
||||
insertInHead(f_tnode->home, p_node);
|
||||
c_tnode->father = f_tnode;
|
||||
c_tnode->room = p_node;
|
||||
f_tnode->child_num++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int addChildInRight(TNode *f_tnode, TNode *c_tnode) {
|
||||
Node *p_node = initNode();
|
||||
initMallocValueForNode(p_node, "pointer", c_tnode);
|
||||
insertInTail(f_tnode->home, p_node);
|
||||
c_tnode->father = f_tnode;
|
||||
c_tnode->room = p_node;
|
||||
f_tnode->child_num++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
TNode *getBrotherInLeft(TNode *p_tnode) {
|
||||
List *p_home = p_tnode->father->home;
|
||||
Node *p_node = p_tnode->room;
|
||||
unsigned long long index = getIndexByNode(p_home, p_node);
|
||||
if (index > 0) return (TNode *)(findByIndexForNode(p_home, index - 1)->value);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TNode *getBrotherInRight(TNode *p_tnode) {
|
||||
List *p_home = p_tnode->father->home;
|
||||
Node *p_node = p_home->head;
|
||||
unsigned long long index = getIndexByNode(p_home, p_node);
|
||||
if (index < p_home->length - 1) return (TNode *)(findByIndexForNode(p_home, index + 1)->value);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int removeChildInLeft(TNode *p_tnode) {
|
||||
TNode *c_tnode = (TNode *)p_tnode->home->head->value;
|
||||
c_tnode->father = NULL;
|
||||
releaseOnlyNode(c_tnode->room);
|
||||
c_tnode->room = NULL;
|
||||
p_tnode->child_num--;
|
||||
popFromHead(p_tnode->home);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int removeChildInRight(TNode *p_tnode) {
|
||||
TNode *c_tnode = (TNode *)p_tnode->home->tail->value;
|
||||
c_tnode->father = NULL;
|
||||
releaseOnlyNode(c_tnode->room);
|
||||
c_tnode->room = NULL;
|
||||
p_tnode->child_num--;
|
||||
popFromTail(p_tnode->home);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
TNode *getChildById(TNode *p_tnode, unsigned long long id) {
|
||||
List *p_home = p_tnode->home;
|
||||
target_id = 0;
|
||||
target_value_id = NULL;
|
||||
listThrough(p_home, _dogetChildById);
|
||||
if (target_value_id != NULL) {
|
||||
return target_value_id;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int _dogetChildById(const char *type, void *value) {
|
||||
if (!strcmp(type, "pointer")) {
|
||||
TNode *p_tode = (TNode *)value;
|
||||
if (p_tode->id == target_id) {
|
||||
target_value_id = p_tode;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *target_type = NULL;
|
||||
void *target_value = NULL;
|
||||
TNode *target_value_value = NULL;
|
||||
int _dogetChildByValue(const char *type, void *value);
|
||||
|
||||
TNode *getChildByValue(TNode *p_tnode, char *type, void *value) {
|
||||
List *p_home = p_tnode->home;
|
||||
target_value = value;
|
||||
target_type = type;
|
||||
target_value_value = NULL;
|
||||
listThrough(p_home, _dogetChildByValue);
|
||||
if (target_value_value != NULL) {
|
||||
return target_value_value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int _dogetChildByValue(const char *type, void *value) {
|
||||
if (!strcmp(type, target_type)) {
|
||||
TNode *p_tode = (TNode *)value;
|
||||
if (!strcmp((char *)target_value, "int")) {
|
||||
if (*(int *)p_tode->value == *(int *)target_value)
|
||||
{
|
||||
target_value_value = p_tode;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp((char *)target_value, "double"))
|
||||
{
|
||||
if (*(double *)p_tode->value == *(double *)target_value)
|
||||
{
|
||||
target_value_value = p_tode;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp((char *)target_value, "string"))
|
||||
{
|
||||
if (!strcmp((char *)p_tode->value, (char *)target_value))
|
||||
{
|
||||
target_value_value = p_tode;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp((char *)target_value, "pointer"))
|
||||
{
|
||||
if (p_tode->value == target_value)
|
||||
{
|
||||
target_value_value = p_tode;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int removeChildById(TNode *p_tnode, unsigned long long id) {
|
||||
TNode *t_tnode = getChildById(p_tnode, id);
|
||||
if (t_tnode != NULL) {
|
||||
TNode *p_fnode = t_tnode->father;
|
||||
p_fnode->child_num--;
|
||||
removeById(p_fnode->home, t_tnode->room->id);
|
||||
releaseOnlyNode(t_tnode->room);
|
||||
t_tnode->room = NULL;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int removeChildByValue(TNode *p_tnode, char *type, void *value) {
|
||||
TNode *t_tnode = getChildByValue(p_tnode, type, value);
|
||||
if (t_tnode != NULL) {
|
||||
TNode *p_fnode = t_tnode->father;
|
||||
p_fnode->child_num--;
|
||||
removeById(p_fnode->home, t_tnode->room->id);
|
||||
releaseOnlyNode(t_tnode->room);
|
||||
t_tnode->room = NULL;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
TNode *getChildByIndex(TNode *p_tnode, unsigned long long index) {
|
||||
List *p_home = p_tnode->home;
|
||||
Node *p_node = p_home->head;
|
||||
int m_index = 0;
|
||||
if (index < p_tnode->child_num)
|
||||
{
|
||||
while (p_node != NULL && m_index < index) {
|
||||
m_index++;
|
||||
p_node = p_node->next;
|
||||
}
|
||||
return (TNode *)p_node->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode) {
|
||||
List *p_home = f_tnode->home;
|
||||
Node *p_node = p_home->head;
|
||||
int m_index = 0;
|
||||
while (p_node != NULL) {
|
||||
TNode *p_tnode = (TNode *)p_node->value;
|
||||
if (p_tnode->id == c_tnode->id) {
|
||||
return m_index;
|
||||
}
|
||||
m_index++;
|
||||
p_node = p_node->next;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int removeChildByIndex(TNode *p_tnode, unsigned long long index) {
|
||||
TNode *t_tnode = getChildByIndex(p_tnode, index);
|
||||
if (t_tnode != NULL) {
|
||||
TNode *p_fnode = t_tnode->father;
|
||||
p_fnode->child_num--;
|
||||
removeById(p_fnode->home, t_tnode->room->id);
|
||||
releaseOnlyNode(t_tnode->room);
|
||||
t_tnode->room = NULL;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
|
||||
int i;
|
||||
TNode *p_tnode = p_tree->root;
|
||||
if (p_tnode != NULL) {
|
||||
if (p_tnode->child_num > 0) {
|
||||
for (i = 0; i < p_tnode->child_num; i++) {
|
||||
if (_doTreeThroughUp(getChildByIndex(p_tnode, i), 1, func) == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
func(p_tnode, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) {
|
||||
int i, func_back;
|
||||
|
||||
if (p_tnode->child_num > 0) {
|
||||
for (i = 0; i < p_tnode->child_num; i++) {
|
||||
if (_doTreeThroughUp(getChildByIndex(p_tnode, i), height + 1, func)) return -1;
|
||||
}
|
||||
}
|
||||
func_back = func(p_tnode, height);
|
||||
if (func_back == -1)return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
|
||||
int i;
|
||||
TNode *p_tnode = p_tree->root;
|
||||
if (p_tree->root != NULL) {
|
||||
func(p_tnode, 0);
|
||||
if (p_tree->root->child_num > 0) {
|
||||
for (i = 0; i < p_tnode->child_num; i++) {
|
||||
if (_doTreeThroughDown(getChildByIndex(p_tnode, i), 1, func) == -1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height)) {
|
||||
int i;
|
||||
int func_back = func(p_tnode, height);
|
||||
if (p_tnode->child_num > 0) {
|
||||
for (i = 0; i < p_tnode->child_num; i++) {
|
||||
if (_doTreeThroughDown(getChildByIndex(p_tnode, i), height + 1, func)) return -1;
|
||||
}
|
||||
}
|
||||
if (func_back == -1)return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height)) {
|
||||
TNode *p_tnode = p_tree->root;
|
||||
unsigned long long height = 0;
|
||||
if (p_tnode != NULL) {
|
||||
int func_back = func(p_tnode, height);
|
||||
while (func_back > -2) {
|
||||
if (func_back > -1) {
|
||||
p_tnode = getChildByIndex(p_tnode, func_back);
|
||||
func(p_tnode, height + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
p_tnode = p_tnode->father;
|
||||
func(p_tnode, height - 1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int releaseTNode(TNode *p_tnode) {
|
||||
if (p_tnode->child_num == 0) {
|
||||
releaseList(p_tnode->home);
|
||||
if (p_tnode->father != NULL) {
|
||||
removeChildById(p_tnode->father, p_tnode->id);
|
||||
}
|
||||
if (strcmp(p_tnode->type, "pointer")) {
|
||||
if (!strcmp(p_tnode->type, "list")) {
|
||||
releaseList((List *)p_tnode->value);
|
||||
}
|
||||
else {
|
||||
free(p_tnode->value);
|
||||
}
|
||||
}
|
||||
p_tnode->value = NULL;
|
||||
p_tnode->type = NULL;
|
||||
p_tnode->id = 0;
|
||||
p_tnode->if_malloc = 0;
|
||||
free(p_tnode);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int releaseTree(Tree *p_tree) {
|
||||
TreeThroughUp(p_tree, _doreleaseTree);
|
||||
p_tree->root = NULL;
|
||||
p_tree->id = 0;
|
||||
free(p_tree);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _doreleaseTree(TNode *p_tnode, unsigned long long height) {
|
||||
releaseTNode(p_tnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int releaseOnlyTree(Tree *p_tree) {
|
||||
p_tree->id = 0;
|
||||
p_tree->root = NULL;
|
||||
free(p_tree);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int releaseOnlyTNode(TNode *p_tnode) {
|
||||
releaseList(p_tnode->home);
|
||||
if (p_tnode->if_malloc) {
|
||||
if (strcmp(p_tnode->type, "pointer")) {
|
||||
if (!strcmp(p_tnode->type, "list")) {
|
||||
releaseList((List *)p_tnode->value);
|
||||
}
|
||||
else {
|
||||
free(p_tnode->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
p_tnode->value = NULL;
|
||||
p_tnode->type = NULL;
|
||||
p_tnode->id = 0;
|
||||
p_tnode->if_malloc = 0;
|
||||
free(p_tnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int releaseAllForTree(void) {
|
||||
Node *p_node;
|
||||
Tree *p_tree;
|
||||
if (if_safeModeForTree) {
|
||||
if_safeModeForTree = 0;
|
||||
p_node = tnode_list->head;
|
||||
while (p_node != NULL) {
|
||||
TNode *p_tnode = (TNode *)p_node->value;
|
||||
releaseOnlyTNode(p_tnode);
|
||||
p_node = p_node->next;
|
||||
}
|
||||
p_node = tree_list->head;
|
||||
while (p_node != NULL) {
|
||||
p_tree = (Tree *)p_node->value;
|
||||
releaseOnlyTree(p_tree);
|
||||
p_node = p_node->next;
|
||||
}
|
||||
releaseList(tnode_list);
|
||||
releaseList(tree_list);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setRoot(Tree *p_tree, TNode *p_tnode) {
|
||||
p_tree->root = p_tnode;
|
||||
return 0;
|
||||
}
|
||||
|
78
tree/tree.h
78
tree/tree.h
@ -1,3 +1,4 @@
|
||||
<<<<<<< HEAD
|
||||
//
|
||||
// tree.h
|
||||
// ZE-Standard-Libraries
|
||||
@ -8,7 +9,78 @@
|
||||
|
||||
#ifndef tree_h
|
||||
#define tree_h
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#endif /* tree_h */
|
||||
#include "../list/list_expand.h"
|
||||
#ifndef TREE_H
|
||||
#define TREE_H
|
||||
|
||||
typedef struct tree_node
|
||||
{
|
||||
unsigned long long id;
|
||||
List *home;
|
||||
struct tree_node *father;
|
||||
Node *room;
|
||||
unsigned long long child_num;
|
||||
char *type;
|
||||
void *value;
|
||||
int if_malloc;
|
||||
}TNode;
|
||||
|
||||
typedef struct tree
|
||||
{
|
||||
unsigned long long id;
|
||||
TNode *root;
|
||||
}Tree;
|
||||
|
||||
|
||||
int safeModeForTree(int ifon);
|
||||
int releaseAllForTree(void);
|
||||
|
||||
TNode *initTNode(void);
|
||||
Tree *initTree(void);
|
||||
int *initMallocValueForTNode(TNode *p_tnode, char *type, void *value);
|
||||
|
||||
int addChildInLeft(TNode *f_tnode, TNode *c_tnode);
|
||||
int addChildInRight(TNode *f_tnode, TNode *c_tnode);
|
||||
TNode *getBrotherInLeft(TNode *p_tnode);
|
||||
TNode *getBrotherInRight(TNode *p_node);
|
||||
int removeChildInLeft(TNode *p_tnode);
|
||||
int removeChildInRight(TNode *p_tnode);
|
||||
TNode *getChildById(TNode *p_tnode, unsigned long long id);
|
||||
TNode *getChildByValue(TNode *p_tnode, char *type, void *value);
|
||||
TNode *getChildByIndex(TNode *p_tnode, unsigned long long index);
|
||||
unsigned long long getIndexByChild(TNode *f_tnode, TNode *c_tnode);
|
||||
int removeChildById(TNode *p_tnode, unsigned long long id);
|
||||
int removeChildByIndex(TNode *p_tnode, unsigned long long index);
|
||||
int removeChildByValue(TNode *p_tnode, char *type, void *value);
|
||||
int TreeThroughDown(Tree *p_tree, int(*func)(TNode *, unsigned long long height));
|
||||
int TreeThroughUp(Tree *p_tree, int(*func)(TNode *, unsigned long long height));
|
||||
int TreeTravel(Tree *p_tree, int(*func)(TNode *, unsigned long long height));
|
||||
|
||||
static int _dogetChildById(const char *type, void *value);
|
||||
static int _dogetChildByValue(const char *type, void *value);
|
||||
static int _doreleaseTree(TNode *p_tnode, unsigned long long height);
|
||||
static int _doTreeThroughDown(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height));
|
||||
static int _doTreeThroughUp(TNode *p_tnode, int height, int(*func)(TNode *, unsigned long long height));
|
||||
|
||||
int releaseTree(Tree *p_tree);
|
||||
int releaseOnlyTree(Tree *p_tree);
|
||||
int releaseTNode(TNode *p_tnode);
|
||||
static int releaseOnlyTNode(TNode *p_tnode);
|
||||
|
||||
int setRoot(Tree *p_tree, TNode *p_tnode);
|
||||
|
||||
static char *target_type;
|
||||
static void *target_value;
|
||||
static TNode *target_value_value;
|
||||
|
||||
static unsigned long long target_id;
|
||||
static TNode *target_value_id;
|
||||
|
||||
static List *tree_list;
|
||||
static List *tnode_list;
|
||||
static int if_safeModeForTree;
|
||||
|
||||
|
||||
#endif
|
||||
>>>>>>> 30b15314d8173f7cdfb24ab7f9250435ae2db90c
|
||||
|
214
tree/tree_expand.c
Normal file
214
tree/tree_expand.c
Normal file
@ -0,0 +1,214 @@
|
||||
#include "tree_expand.h"
|
||||
|
||||
TNode *tnodeWithInt(int temp) {
|
||||
TNode *p_tnode = initTNode();
|
||||
int *p_temp = (int *)malloc(sizeof(int));
|
||||
*p_temp = temp;
|
||||
initMallocValueForTNode(p_tnode, "int", p_temp);
|
||||
return p_tnode;
|
||||
}
|
||||
|
||||
TNode *tnodeWithDouble(double temp) {
|
||||
TNode *p_tnode = initTNode();
|
||||
double *p_temp = (double *)malloc(sizeof(double));
|
||||
*p_temp = temp;
|
||||
initMallocValueForTNode(p_tnode, "double", p_temp);
|
||||
return p_tnode;
|
||||
}
|
||||
TNode *tnodeWithString(char *temp) {
|
||||
TNode *p_tnode = initTNode();
|
||||
char *p_temp = (char *)malloc(sizeof(temp));
|
||||
strcpy_s(p_temp, sizeof(p_temp), temp);
|
||||
initMallocValueForTNode(p_tnode, "double", p_temp);
|
||||
return p_tnode;
|
||||
}
|
||||
|
||||
TNode *tnodeWithPointer(void *temp) {
|
||||
TNode *p_tnode = initTNode();
|
||||
initMallocValueForTNode(p_tnode, "pointer", temp);
|
||||
return p_tnode;
|
||||
}
|
||||
|
||||
int getValueByIntForTree(TNode *p_tnode) {
|
||||
if (!strcmp(p_tnode->type, "int")) {
|
||||
return *(int *)p_tnode->value;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
double getValueByDoubleForTree(TNode *p_tnode) {
|
||||
if (!strcmp(p_tnode->type, "double")) {
|
||||
return *(double *)p_tnode->value;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *getValueByStringForTree(TNode *p_tnode) {
|
||||
if (!strcmp(p_tnode->type, "string")) {
|
||||
return (char *)p_tnode->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *getValueByPointerForTree(TNode *p_tnode) {
|
||||
if (!strcmp(p_tnode->type, "pointer")) {
|
||||
return p_tnode->value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int printTNode(TNode *p_tnode, int priority) {
|
||||
int i;
|
||||
if (p_tnode != NULL) {
|
||||
for (i = 0; i < priority; i++) printf(" ");
|
||||
if (priority == 0) printf("###");
|
||||
else printf("#");
|
||||
|
||||
printf("TNode(id: %llu)\n", p_tnode->id);
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("ifMalloc: ");
|
||||
if (p_tnode->if_malloc) {
|
||||
printf("YES\n");
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Value(type: %s): ", p_tnode->type);
|
||||
if (!strcmp(p_tnode->type, "int")) {
|
||||
printf("%d\n", *(int *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "double")) {
|
||||
printf("%a\n", *(double *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "string")) {
|
||||
printf("%s\n", (char *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "pointer")) {
|
||||
printf("%p\n", (char *)(p_tnode->value));
|
||||
}
|
||||
}
|
||||
else printf("NO\n");
|
||||
|
||||
if (p_tnode->child_num > 0) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Child number: %llu\n", p_tnode->child_num);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int printTNodeWithHome(TNode *p_tnode,int priority) {
|
||||
int i;
|
||||
List *p_home;
|
||||
Node *p_node;
|
||||
if (p_tnode != NULL) {
|
||||
if (priority == 0) printf("###");
|
||||
else printf("#");
|
||||
printf("TNode(id: %llu)\n", p_tnode->id);
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("ifMalloc: ");
|
||||
if (p_tnode->if_malloc) {
|
||||
printf("YES\n");
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Value(type: %s): ", p_tnode->type);
|
||||
if (!strcmp(p_tnode->type, "int")) {
|
||||
printf("%d\n", *(int *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "double")) {
|
||||
printf("%a\n", *(double *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "string")) {
|
||||
printf("%s\n", (char *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "pointer")) {
|
||||
printf("%p\n", (char *)(p_tnode->value));
|
||||
}
|
||||
}
|
||||
else printf("NO\n");
|
||||
|
||||
if (p_tnode->father != NULL) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Father id: %llu\n", p_tnode->father->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Father: NO\n");
|
||||
}
|
||||
|
||||
if (p_tnode->child_num > 0) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Child(number: %llu):\n", p_tnode->child_num);
|
||||
}
|
||||
|
||||
p_home = p_tnode->home;
|
||||
p_node = p_home->head;
|
||||
while (p_node != NULL) {
|
||||
printTNode((TNode *)p_node->value, priority + 2);
|
||||
p_node = p_node->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int printTNodeWithFamily(TNode *p_tnode, int priority) {
|
||||
int i;
|
||||
List *p_home;
|
||||
Node *p_node;
|
||||
if (p_tnode != NULL) {
|
||||
for (i = 0; i < priority; i++) printf(" ");
|
||||
if (priority == 0) printf("###");
|
||||
else printf("#");
|
||||
printf("TNode(id: %llu)\n", p_tnode->id);
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("ifMalloc: ");
|
||||
if (p_tnode->if_malloc) {
|
||||
printf("YES\n");
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Value(type: %s): ", p_tnode->type);
|
||||
if (!strcmp(p_tnode->type, "int")) {
|
||||
printf("%d\n", *(int *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "double")) {
|
||||
printf("%a\n", *(double *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "string")) {
|
||||
printf("%s\n", (char *)(p_tnode->value));
|
||||
}
|
||||
else if (!strcmp(p_tnode->type, "pointer")) {
|
||||
printf("%p\n", (char *)(p_tnode->value));
|
||||
}
|
||||
}
|
||||
else printf("NO\n");
|
||||
|
||||
if (p_tnode->father != NULL) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Father id: %llu\n", p_tnode->father->id);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Father: NO\n");
|
||||
}
|
||||
|
||||
if (p_tnode->child_num > 0) {
|
||||
for (i = 0; i < priority + 1; i++) printf(" ");
|
||||
printf("Child(number: %llu):\n", p_tnode->child_num);
|
||||
}
|
||||
|
||||
p_home = p_tnode->home;
|
||||
p_node = p_home->head;
|
||||
while (p_node != NULL) {
|
||||
printTNodeWithFamily((TNode *)p_node->value, priority + 2);
|
||||
p_node = p_node->next;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int printTree(Tree *p_tree) {
|
||||
printf("###");
|
||||
printf("Tree(id: %llu)",p_tree->id);
|
||||
printTNodeWithFamily(p_tree->root,0);
|
||||
return 0;
|
||||
}
|
21
tree/tree_expand.h
Normal file
21
tree/tree_expand.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef TREE_EXPAND_H
|
||||
#define TREE_EXPAND_H
|
||||
|
||||
#include "tree.h"
|
||||
|
||||
TNode *tnodeWithInt(int);
|
||||
TNode *tnodeWithDouble(double);
|
||||
TNode *tnodeWithString(char *);
|
||||
TNode *tnodeWithPointer(void *);
|
||||
|
||||
int getValueByIntForTree(TNode *);
|
||||
double getValueByDoubleForTree(TNode *);
|
||||
char *getValueByStringForTree(TNode *);
|
||||
void *getValueByPointerForTree(TNode *);
|
||||
|
||||
int printTree(Tree *p_tree);
|
||||
int printTNodeWithHome(TNode *p_tnode, int priority);
|
||||
int printTNodeWithFamily(TNode *p_tnode, int priority);
|
||||
int printTNode(TNode *p_tnode, int priority);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user