forked from wangzheng0822/algo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add implementations of array in python and objective-c
- Loading branch information
1 parent
4d1525b
commit f8c9f0b
Showing
11 changed files
with
498 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// MyArray.h | ||
// algo | ||
// | ||
// Created by Wenru Dong on 2018/10/3. | ||
// Copyright © 2018年 Wenru Dong. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface MyArray : NSObject | ||
|
||
- (instancetype)initWithCapacity:(NSUInteger)capacity; | ||
- (id)objectAtIndexedSubscript:(NSUInteger)index; | ||
- (void)removeObjectAtIndex:(NSUInteger)index; | ||
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index; | ||
- (void)addObject:(id)anObject; | ||
- (void)printAll; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// MyArray.m | ||
// algo | ||
// | ||
// Created by Wenru Dong on 2018/10/3. | ||
// Copyright © 2018年 Wenru Dong. All rights reserved. | ||
// | ||
|
||
#import "MyArray.h" | ||
|
||
@implementation MyArray | ||
{ | ||
@private | ||
NSMutableArray *_data; | ||
NSUInteger _capacity; | ||
NSUInteger _count; | ||
} | ||
|
||
- (instancetype)initWithCapacity:(NSUInteger)capacity { | ||
self = [super init]; | ||
if (self) { | ||
_data = [NSMutableArray arrayWithCapacity:capacity]; | ||
_capacity = capacity; | ||
_count = 0; | ||
} | ||
return self; | ||
} | ||
|
||
- (id)objectAtIndexedSubscript:(NSUInteger)index { | ||
if (index >= _count) return nil; | ||
return _data[index]; | ||
} | ||
|
||
- (void)removeObjectAtIndex:(NSUInteger)index { | ||
if (index >= _count) { | ||
[NSException raise:NSRangeException format:@"Index out of range."]; | ||
} | ||
for (NSUInteger i = index + 1; i < _data.count; i++) { | ||
_data[i-1] = _data[i]; | ||
} | ||
_count--; | ||
} | ||
|
||
- (void)insertObject:(nonnull id)anObject atIndex:(NSUInteger)index { | ||
if (index >= _count || _count == _capacity) { | ||
[NSException raise:NSRangeException format:@"Index out of range."]; | ||
} | ||
for (NSUInteger i = _count - 1; i >= index; i--) { | ||
_data[i+1] = _data[i]; | ||
} | ||
_data[index] = anObject; | ||
_count++; | ||
} | ||
|
||
// insertToTail | ||
- (void)addObject:(nonnull id)anObject { | ||
if (_count == _capacity) { | ||
[NSException raise:NSRangeException format:@"Array is full."]; | ||
} | ||
[_data addObject:anObject]; | ||
_count++; | ||
} | ||
|
||
- (void)printAll { | ||
for (id obj in _data) { | ||
NSLog(@"%@", obj); | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,277 @@ | ||
// !$*UTF8*$! | ||
{ | ||
archiveVersion = 1; | ||
classes = { | ||
}; | ||
objectVersion = 50; | ||
objects = { | ||
|
||
/* Begin PBXBuildFile section */ | ||
80EF91E12165521D00600B1E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 80EF91E02165521D00600B1E /* main.m */; }; | ||
/* End PBXBuildFile section */ | ||
|
||
/* Begin PBXCopyFilesBuildPhase section */ | ||
80EF91DB2165521D00600B1E /* CopyFiles */ = { | ||
isa = PBXCopyFilesBuildPhase; | ||
buildActionMask = 2147483647; | ||
dstPath = /usr/share/man/man1/; | ||
dstSubfolderSpec = 0; | ||
files = ( | ||
); | ||
runOnlyForDeploymentPostprocessing = 1; | ||
}; | ||
/* End PBXCopyFilesBuildPhase section */ | ||
|
||
/* Begin PBXFileReference section */ | ||
80EF91DD2165521D00600B1E /* algo */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = algo; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
80EF91E02165521D00600B1E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; | ||
/* End PBXFileReference section */ | ||
|
||
/* Begin PBXFrameworksBuildPhase section */ | ||
80EF91DA2165521D00600B1E /* Frameworks */ = { | ||
isa = PBXFrameworksBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXFrameworksBuildPhase section */ | ||
|
||
/* Begin PBXGroup section */ | ||
80EF91D42165521D00600B1E = { | ||
isa = PBXGroup; | ||
children = ( | ||
80EF91DF2165521D00600B1E /* algo */, | ||
80EF91DE2165521D00600B1E /* Products */, | ||
); | ||
sourceTree = "<group>"; | ||
}; | ||
80EF91DE2165521D00600B1E /* Products */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
80EF91DD2165521D00600B1E /* algo */, | ||
); | ||
name = Products; | ||
sourceTree = "<group>"; | ||
}; | ||
80EF91DF2165521D00600B1E /* algo */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
80EF91E02165521D00600B1E /* main.m */, | ||
); | ||
path = algo; | ||
sourceTree = "<group>"; | ||
}; | ||
/* End PBXGroup section */ | ||
|
||
/* Begin PBXNativeTarget section */ | ||
80EF91DC2165521D00600B1E /* algo */ = { | ||
isa = PBXNativeTarget; | ||
buildConfigurationList = 80EF91E42165521D00600B1E /* Build configuration list for PBXNativeTarget "algo" */; | ||
buildPhases = ( | ||
80EF91D92165521D00600B1E /* Sources */, | ||
80EF91DA2165521D00600B1E /* Frameworks */, | ||
80EF91DB2165521D00600B1E /* CopyFiles */, | ||
); | ||
buildRules = ( | ||
); | ||
dependencies = ( | ||
); | ||
name = algo; | ||
productName = algo; | ||
productReference = 80EF91DD2165521D00600B1E /* algo */; | ||
productType = "com.apple.product-type.tool"; | ||
}; | ||
/* End PBXNativeTarget section */ | ||
|
||
/* Begin PBXProject section */ | ||
80EF91D52165521D00600B1E /* Project object */ = { | ||
isa = PBXProject; | ||
attributes = { | ||
LastUpgradeCheck = 0940; | ||
ORGANIZATIONNAME = "Wenru Dong"; | ||
TargetAttributes = { | ||
80EF91DC2165521D00600B1E = { | ||
CreatedOnToolsVersion = 9.4.1; | ||
}; | ||
}; | ||
}; | ||
buildConfigurationList = 80EF91D82165521D00600B1E /* Build configuration list for PBXProject "algo" */; | ||
compatibilityVersion = "Xcode 9.3"; | ||
developmentRegion = en; | ||
hasScannedForEncodings = 0; | ||
knownRegions = ( | ||
en, | ||
); | ||
mainGroup = 80EF91D42165521D00600B1E; | ||
productRefGroup = 80EF91DE2165521D00600B1E /* Products */; | ||
projectDirPath = ""; | ||
projectRoot = ""; | ||
targets = ( | ||
80EF91DC2165521D00600B1E /* algo */, | ||
); | ||
}; | ||
/* End PBXProject section */ | ||
|
||
/* Begin PBXSourcesBuildPhase section */ | ||
80EF91D92165521D00600B1E /* Sources */ = { | ||
isa = PBXSourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
80EF91E12165521D00600B1E /* main.m in Sources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXSourcesBuildPhase section */ | ||
|
||
/* Begin XCBuildConfiguration section */ | ||
80EF91E22165521D00600B1E /* 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; | ||
}; | ||
80EF91E32165521D00600B1E /* 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; | ||
}; | ||
80EF91E52165521D00600B1E /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
CODE_SIGN_STYLE = Automatic; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
}; | ||
name = Debug; | ||
}; | ||
80EF91E62165521D00600B1E /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
CODE_SIGN_STYLE = Automatic; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
}; | ||
name = Release; | ||
}; | ||
/* End XCBuildConfiguration section */ | ||
|
||
/* Begin XCConfigurationList section */ | ||
80EF91D82165521D00600B1E /* Build configuration list for PBXProject "algo" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
80EF91E22165521D00600B1E /* Debug */, | ||
80EF91E32165521D00600B1E /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
80EF91E42165521D00600B1E /* Build configuration list for PBXNativeTarget "algo" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
80EF91E52165521D00600B1E /* Debug */, | ||
80EF91E62165521D00600B1E /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
/* End XCConfigurationList section */ | ||
}; | ||
rootObject = 80EF91D52165521D00600B1E /* Project object */; | ||
} |
7 changes: 7 additions & 0 deletions
7
object-c/05_array/algo/algo.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...-c/05_array/algo/algo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Binary file added
BIN
+5.06 KB
...eproj/project.xcworkspace/xcuserdata/wenrudong.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Oops, something went wrong.