├── .gitignore ├── Algorithms ├── DivideConquer(分治) │ ├── DivideConquer(分治).xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── DivideConquer(分治) │ │ ├── CWDivideConquer.h │ │ ├── CWDivideConquer.m │ │ └── main.m ├── Greedy(贪心策略) │ ├── Greedy(贪心策略).xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Greedy(贪心策略) │ │ ├── CWGreedy.h │ │ ├── CWGreedy.m │ │ ├── main.m │ │ └── 贪心背包案例.png ├── MinShortPathAlgorithms │ ├── 01-最短路径 │ │ ├── 01-最短路径.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── 01-最短路径 │ │ │ ├── Bellman-Ford参考1.png │ │ │ ├── Bellman-Ford参考2.png │ │ │ ├── CWBinaryHeap.h │ │ │ ├── CWBinaryHeap.m │ │ │ ├── CWGraph.h │ │ │ ├── CWGraph.m │ │ │ ├── CWQueueList.h │ │ │ ├── CWQueueList.m │ │ │ ├── CWStackList.h │ │ │ ├── CWStackList.m │ │ │ ├── Dijkstra算法参考图.png │ │ │ └── main.m │ └── README.md ├── MinTreeAlgorithms │ ├── 00-拓扑排序 │ │ ├── MinTreeAlgorithms.xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── MinTreeAlgorithms │ │ │ ├── CWGraph.h │ │ │ ├── CWGraph.m │ │ │ ├── CWQueueList.h │ │ │ ├── CWQueueList.m │ │ │ ├── CWStackList.h │ │ │ ├── CWStackList.m │ │ │ └── main.m │ ├── 01-Kruskal算法(最小生成树) │ │ ├── 01-Kruskal算法(最小生成树).xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── 01-Kruskal算法(最小生成树) │ │ │ ├── CWBinaryHeap.h │ │ │ ├── CWBinaryHeap.m │ │ │ ├── CWGoodUnionFind.h │ │ │ ├── CWGoodUnionFind.m │ │ │ ├── CWGraph.h │ │ │ ├── CWGraph.m │ │ │ ├── CWQueueList.h │ │ │ ├── CWQueueList.m │ │ │ ├── CWStackList.h │ │ │ ├── CWStackList.m │ │ │ ├── main.m │ │ │ ├── 参考图片1.png │ │ │ └── 参考图片2.png │ ├── 02-Prim算法(最小生成树) │ │ ├── 02-Prim算法(最小生成树).xcodeproj │ │ │ ├── project.pbxproj │ │ │ └── project.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ └── 02-Prim算法(最小生成树) │ │ │ ├── CWBinaryHeap.h │ │ │ ├── CWBinaryHeap.m │ │ │ ├── CWGoodUnionFind.h │ │ │ ├── CWGoodUnionFind.m │ │ │ ├── CWGraph.h │ │ │ ├── CWGraph.m │ │ │ ├── CWQueueList.h │ │ │ ├── CWQueueList.m │ │ │ ├── CWStackList.h │ │ │ ├── CWStackList.m │ │ │ ├── main.m │ │ │ ├── 参考图片1-1.png │ │ │ ├── 参考图片1-2.png │ │ │ └── 参考图片2.png │ └── README.md ├── NumsQueue(回溯) │ ├── NumsQueue(回溯).xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── NumsQueue(回溯) │ │ ├── CWNumsQueue.h │ │ ├── CWNumsQueue.m │ │ ├── CWNumsQueue2.h │ │ ├── CWNumsQueue2.m │ │ └── main.m ├── Recursive │ ├── Recursive.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Recursive │ │ ├── CWRecursive.h │ │ ├── CWRecursive.m │ │ └── main.m └── SortAlgorithms │ ├── 00-排序(Sort) │ ├── 00-排序(Sort).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ └── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── chengjinwei.xcuserdatad │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 00-排序(Sort) │ │ ├── CWMaxBinaryHeap.h │ │ ├── CWMaxBinaryHeap.m │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 01-冒泡排序(Bubble Sort) │ ├── 01-冒泡排序.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ ├── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ │ └── mac.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ ├── xcdebugger │ │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ │ └── mac.xcuserdatad │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 01-冒泡排序 │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 02-选择排序(Selection Sort) │ ├── 01-SelectSort.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ ├── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ │ └── mac.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ │ └── mac.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 01-SelectSort │ │ ├── CWMaxBinaryHeap.h │ │ ├── CWMaxBinaryHeap.m │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 03-插入排序(Insert Sort) │ ├── 03-插入排序(Insert).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ ├── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ │ └── mac.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ │ └── mac.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 03-插入排序(Insert) │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 04-归并排序(Merge Sort) │ ├── 04-归并排序(Merge Sort).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ └── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── chengjinwei.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 04-归并排序(Merge Sort) │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 05-快速排序(QuickSort) │ ├── 05-快速排序(QuickSort).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ └── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── chengjinwei.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 05-快速排序(QuickSort) │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 06-希尔排序(ShellSort) │ ├── 06-希尔排序(ShellSort).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ └── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── chengjinwei.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 06-希尔排序(ShellSort) │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 07-计数排序(CountingSort) │ ├── 07-计数排序(CountingSort).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ └── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── chengjinwei.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 07-计数排序(CountingSort) │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 08-基数排序(RedixSort) │ ├── 08-基数排序(RedixSort).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ ├── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ │ └── mac.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── xcschemes │ │ │ │ └── xcschememanagement.plist │ │ │ └── mac.xcuserdatad │ │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 08-基数排序(RedixSort) │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── 09-桶排序(BucketSort) │ ├── 09-桶排序(BucketSort).xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ ├── xcshareddata │ │ │ │ └── IDEWorkspaceChecks.plist │ │ │ └── xcuserdata │ │ │ │ └── chengjinwei.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── chengjinwei.xcuserdatad │ │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ └── 09-桶排序(BucketSort) │ │ ├── CWTimeTool.h │ │ ├── CWTimeTool.m │ │ └── main.m │ ├── README.md │ └── Resource │ ├── BubbleSortResult.jpg │ ├── InsertSortResult.jpg │ ├── MergeSortResult.jpg │ └── SelectSortResult.jpg ├── README.md └── Structures ├── 01-复杂度 ├── 01-复杂度.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 01-复杂度 │ ├── CWFibObject.h │ ├── CWFibObject.m │ ├── CWTimeTool.h │ ├── CWTimeTool.m │ └── main.m ├── 02-动态数组(Dynamic) ├── 02-动态数组(Dynamic).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 02-动态数组(Dynamic) │ ├── CWArrayList.h │ ├── CWArrayList.m │ ├── CWArrayListEModel.h │ ├── CWArrayListEModel.m │ └── main.m ├── 03-链表 ├── 03-链表.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03-链表 │ ├── CWListNode.h │ ├── CWListNode.m │ └── main.m ├── 04-双向链表 ├── 04-双向链表.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 04-双向链表 │ ├── CWListNode.h │ ├── CWListNode.m │ ├── main.m │ └── remark.md ├── 05-循环链表 ├── 05-循环链表.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 05-循环链表 │ ├── CWDoubleCycleNode.h │ ├── CWDoubleCycleNode.m │ ├── CWListNode.h │ ├── CWListNode.m │ ├── CWSingleCycleNode.h │ ├── CWSingleCycleNode.m │ └── main.m ├── 06-栈 ├── 06-栈.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 06-栈 │ ├── CWStackList.h │ ├── CWStackList.m │ └── main.m ├── 07-队列 ├── 07-队列.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 07-队列 │ ├── CWCycleQueueList.h │ ├── CWCycleQueueList.m │ ├── CWDoubleCycleQueueList.h │ ├── CWDoubleCycleQueueList.m │ ├── CWDoubleQueueList.h │ ├── CWDoubleQueueList.m │ ├── CWQueueList.h │ ├── CWQueueList.m │ └── main.m ├── 08-二叉搜索树 ├── 08-二叉搜索树.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 08-二叉搜索树 │ ├── CWBSTCompareModel.h │ ├── CWBSTCompareModel.m │ ├── CWBinarySearchTree.h │ ├── CWBinarySearchTree.m │ ├── MJBinaryTrees │ ├── MJBinaryTreeInfo.h │ ├── MJBinaryTrees.h │ ├── MJBinaryTrees.m │ ├── MJPrinter │ │ ├── MJInorderPrinter.h │ │ ├── MJInorderPrinter.m │ │ ├── MJLevelOrderPrinter.h │ │ ├── MJLevelOrderPrinter.m │ │ ├── MJPrinter.h │ │ └── MJPrinter.m │ ├── NSString+Trees.h │ └── NSString+Trees.m │ └── main.m ├── 09-AVL平衡树 ├── 09-AVL平衡树.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 09-AVL平衡树 │ ├── CWAVLBalanceTree.h │ ├── CWAVLBalanceTree.m │ ├── CWAVLCompareModel.h │ ├── CWAVLCompareModel.m │ ├── MJBinaryTrees │ ├── MJBinaryTreeInfo.h │ ├── MJBinaryTrees.h │ ├── MJBinaryTrees.m │ ├── MJPrinter │ │ ├── MJInorderPrinter.h │ │ ├── MJInorderPrinter.m │ │ ├── MJLevelOrderPrinter.h │ │ ├── MJLevelOrderPrinter.m │ │ ├── MJPrinter.h │ │ └── MJPrinter.m │ ├── NSString+Trees.h │ └── NSString+Trees.m │ └── main.m ├── 10-RBT红黑树(RedBlackTree) ├── 10-RBT红黑树(RedBlackTree).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 10-RBT红黑树(RedBlackTree) │ ├── CWRBTCompareModel.h │ ├── CWRBTCompareModel.m │ ├── CWRBTree.h │ ├── CWRBTree.m │ ├── MJBinaryTrees │ ├── MJBinaryTreeInfo.h │ ├── MJBinaryTrees.h │ ├── MJBinaryTrees.m │ ├── MJPrinter │ │ ├── MJInorderPrinter.h │ │ ├── MJInorderPrinter.m │ │ ├── MJLevelOrderPrinter.h │ │ ├── MJLevelOrderPrinter.m │ │ ├── MJPrinter.h │ │ └── MJPrinter.m │ ├── NSString+Trees.h │ └── NSString+Trees.m │ └── main.m ├── 11-集合(Set) ├── 11-集合(Set).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── mac.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 11-集合(Set) │ ├── CWRBSet.h │ ├── CWRBSet.m │ ├── CWRBTCompareModel.h │ ├── CWRBTCompareModel.m │ └── main.m ├── 12-映射(Map) ├── 12-映射(Map).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ ├── xcdebugger │ │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 12-映射(Map) │ ├── CWRBTreeCompare.h │ ├── CWRBTreeCompare.m │ ├── CWRBTreeMap.h │ ├── CWRBTreeMap.m │ ├── MJBinaryTrees │ ├── MJBinaryTreeInfo.h │ ├── MJBinaryTrees.h │ ├── MJBinaryTrees.m │ ├── MJPrinter │ │ ├── MJInorderPrinter.h │ │ ├── MJInorderPrinter.m │ │ ├── MJLevelOrderPrinter.h │ │ ├── MJLevelOrderPrinter.m │ │ ├── MJPrinter.h │ │ └── MJPrinter.m │ ├── NSString+Trees.h │ └── NSString+Trees.m │ └── main.m ├── 13-哈希值(hash) ├── 13-哈希值(hash).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 13-哈希值(hash) │ ├── CWHashMap.h │ ├── CWHashMap.m │ ├── CWHashMapCompare.h │ ├── CWHashMapCompare.m │ ├── CWHashMapModel.h │ ├── CWHashMapModel.m │ ├── MJBinaryTrees │ ├── MJBinaryTreeInfo.h │ ├── MJBinaryTrees.h │ ├── MJBinaryTrees.m │ ├── MJPrinter │ │ ├── MJInorderPrinter.h │ │ ├── MJInorderPrinter.m │ │ ├── MJLevelOrderPrinter.h │ │ ├── MJLevelOrderPrinter.m │ │ ├── MJPrinter.h │ │ └── MJPrinter.m │ ├── NSString+Trees.h │ └── NSString+Trees.m │ └── main.m ├── 14-二叉堆(BinaryHeap) ├── 14-二叉堆(BinaryHeap).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 14-二叉堆(BinaryHeap) │ ├── CWMaxBinaryHeap.h │ ├── CWMaxBinaryHeap.m │ ├── MJBinaryTrees │ ├── MJBinaryTreeInfo.h │ ├── MJBinaryTrees.h │ ├── MJBinaryTrees.m │ ├── MJPrinter │ │ ├── MJInorderPrinter.h │ │ ├── MJInorderPrinter.m │ │ ├── MJLevelOrderPrinter.h │ │ ├── MJLevelOrderPrinter.m │ │ ├── MJPrinter.h │ │ └── MJPrinter.m │ ├── NSString+Trees.h │ └── NSString+Trees.m │ └── main.m ├── 15-优先级队列(Priority Queue) ├── 15-优先级队列(Priority Queue).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 15-优先级队列(Priority Queue) │ ├── CWPriorityQueue.h │ ├── CWPriorityQueue.m │ ├── CWPriorityQueueModel.h │ ├── CWPriorityQueueModel.m │ └── main.m ├── 16-前缀树(Trie) ├── 16-前缀树(Trie).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── mac.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── mac.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 16-前缀树(Trie) │ ├── CWTrie.h │ ├── CWTrie.m │ └── main.m ├── 17-并查集(UnionFind) ├── 17-并查集(UnionFind).xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chengjinwei.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chengjinwei.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 17-并查集(UnionFind) │ ├── CWGoodUnionFind.h │ ├── CWGoodUnionFind.m │ ├── CWTimeTool.h │ ├── CWTimeTool.m │ ├── CWUnionFindSet.h │ ├── CWUnionFindSet.m │ └── main.m └── 18-图(Graph) ├── 18-图(Graph).xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ ├── chengjinwei.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── mac.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── chengjinwei.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ └── xcschememanagement.plist │ └── mac.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist └── 18-图(Graph) ├── CWGraph.h ├── CWGraph.m ├── CWQueueList.h ├── CWQueueList.m ├── CWStackList.h ├── CWStackList.m └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.pbxuser 3 | !default.pbxuser 4 | *.mode1v3 5 | !default.mode1v3 6 | *.mode2v3 7 | !default.mode2v3 8 | *.perspectivev3 9 | !default.perspectivev3 10 | xcuserdata 11 | *.xccheckout 12 | *.moved-aside 13 | DerivedData 14 | *.DS_Store 15 | -------------------------------------------------------------------------------- /Algorithms/DivideConquer(分治)/DivideConquer(分治).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/DivideConquer(分治)/DivideConquer(分治).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/DivideConquer(分治)/DivideConquer(分治)/CWDivideConquer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWDivideConquer.h 3 | // DivideConquer(分治) 4 | // 5 | // Created by mac on 2019/11/14. 6 | // Copyright © 2019年 Mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWDivideConquer : NSObject 12 | 13 | // 1、求最大连续子序列和(-2、1、-3、4、-1、2、1、-5、4)O(n^3) 14 | - (void)maxSubString1:(NSArray *)strings; 15 | 16 | // 2、求最大连续子序列和(-2、1、-3、4、-1、2、1、-5、4)O(n^2) 17 | - (void)maxSubString2:(NSArray *)strings; 18 | 19 | // 3、分治求最大连续子序列和(-2、1、-3、4、-1、2、1、-5、4)O(nlogn) 20 | - (NSInteger)maxSubStrForDivideConquer:(NSArray *)strings; 21 | @end 22 | -------------------------------------------------------------------------------- /Algorithms/DivideConquer(分治)/DivideConquer(分治)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DivideConquer(分治) 4 | // 5 | // Created by mac on 2019/11/14. 6 | // Copyright © 2019年 Mac. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWDivideConquer.h" 11 | int main(int argc, const char * argv[]) { 12 | @autoreleasepool { 13 | 14 | // -2、1、-3、4、-1、2、1、-5、4 15 | NSMutableArray *array = [NSMutableArray arrayWithObjects:@"-2",@"1",@"-3",@"4",@"-1",@"2",@"1",@"-5",@"4", nil]; 16 | CWDivideConquer *divide = [[CWDivideConquer alloc] init]; 17 | [divide maxSubString1:array.copy]; 18 | [divide maxSubString2:array.copy]; 19 | [divide maxSubStrForDivideConquer:array.copy]; 20 | // NSLog(@"%@",results); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Algorithms/Greedy(贪心策略)/Greedy(贪心策略).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/Greedy(贪心策略)/Greedy(贪心策略).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/Greedy(贪心策略)/Greedy(贪心策略)/CWGreedy.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWGreedy.h 3 | // Greedy(贪心策略) 4 | // 5 | // Created by mac on 2019/11/13. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWGreedy : NSObject 12 | // 贪心应用1需求:硬币25、10、5、1,总共需要找41、81,总共需要找最少的硬币的方案 13 | - (void)greedyMethod:(int)sum; 14 | 15 | // 贪心应用2需求:硬币25、20、5、1,总共需要找41、81,总共需要找最少的硬币的方案 16 | - (void)greedyMethod2:(int)sum; 17 | 18 | // 贪心应用3需求:背包0-1问题 19 | - (void)greedyMethod3:(NSString *)title; 20 | 21 | @end 22 | 23 | 24 | @interface CWBackpack:NSObject 25 | 26 | @property(nonatomic,assign)CGFloat weight; 27 | @property(nonatomic,assign)CGFloat price; 28 | @property(nonatomic,assign)CGFloat priceDensity; 29 | // 初始化 30 | - (instancetype)initWithWeight:(CGFloat)weight price:(CGFloat)price; 31 | @end 32 | -------------------------------------------------------------------------------- /Algorithms/Greedy(贪心策略)/Greedy(贪心策略)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Greedy(贪心策略) 4 | // 5 | // Created by mac on 2019/11/13. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWGreedy.h" 11 | int main(int argc, const char * argv[]) { 12 | @autoreleasepool { 13 | CWGreedy *greedy = [[CWGreedy alloc] init]; 14 | // [greedy greedyMethod:41]; 15 | // [greedy greedyMethod:26]; 16 | // [greedy greedyMethod:81]; 17 | 18 | // 2、找零钱:此时的方案,并不一定是最优解(2*20+1*1) 19 | // [greedy greedyMethod2:41]; 20 | 21 | 22 | // 3、背包问题 23 | [greedy greedyMethod3:@"以价格为主导"]; 24 | [greedy greedyMethod3:@"以体重为主导"]; 25 | [greedy greedyMethod3:@"以价格密度为主导"]; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Algorithms/Greedy(贪心策略)/Greedy(贪心策略)/贪心背包案例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/Greedy(贪心策略)/Greedy(贪心策略)/贪心背包案例.png -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/Bellman-Ford参考1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/Bellman-Ford参考1.png -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/Bellman-Ford参考2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/Bellman-Ford参考2.png -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/CWBinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWBinaryHeap.h 3 | // 01-Kruskal算法(最小生成树) 4 | // 5 | // Created by 程金伟 on 2019/10/22. 6 | // Copyright © 2019 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWGraph.h" 11 | 12 | 13 | @interface CWBinaryHeap : NSObject 14 | 15 | @property (nonatomic,assign) int size; 16 | @property (nonatomic,strong) NSMutableArray *binaryHeaps; 17 | @property (nonatomic,assign) BOOL MaxHeap; 18 | 19 | /** 20 | 0、批量建堆 21 | */ 22 | - (void)batchHeaps:(NSArray *)array; 23 | /** 24 | 1、二叉堆的size 25 | */ 26 | - (int)heap_size; 27 | 28 | /** 29 | 2、二叉堆是否为空 30 | */ 31 | - (BOOL)isEmpty; 32 | 33 | /** 34 | 3、二叉堆的清空 35 | */ 36 | - (void)clear; 37 | 38 | /** 39 | 4、二叉堆添加元素 40 | */ 41 | - (void)addEle:(id)ele; 42 | 43 | /** 44 | 5、获取堆顶元素 45 | */ 46 | - (id)getTop; 47 | 48 | /** 49 | 6、删除堆顶元素 50 | */ 51 | - (id)removeTop; 52 | 53 | /** 54 | 7、删除堆顶元素同时插入一个新元素 55 | */ 56 | - (id)replaceTopWithEle:(id)ele; 57 | 58 | @end 59 | 60 | 61 | -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/CWQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 队列特点:只能在队列尾添加、队列头删除元素 13 | **/ 14 | 15 | @interface CWQueueList : NSObject 16 | 17 | /**< 链表子节点数目 */ 18 | @property (nonatomic,assign) int size; 19 | /**< 队列元素 */ 20 | @property (nonatomic,copy) id ele; 21 | 22 | /** 23 | 1、入队(队尾入) 24 | */ 25 | - (void)cw_enQueue:(id)E; 26 | 27 | /** 28 | 2、出队(队头出) 29 | */ 30 | - (id)cw_deQueue; 31 | 32 | /** 33 | 3、出队(队头元素) 34 | */ 35 | - (id)cw_topQueue; 36 | 37 | /** 38 | 4、队列的大小 39 | */ 40 | - (int)cw_size; 41 | 42 | /** 43 | 5、队列是否为空 44 | */ 45 | - (BOOL)cw_isEmpty; 46 | 47 | /** 48 | 6、清空队列数据 49 | */ 50 | - (void)cw_clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/CWStackList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.h 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWStackList : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 数组size */ 14 | 15 | /** 16 | 1、数组的大小 17 | */ 18 | - (int)cw_size; 19 | 20 | /** 21 | 2、数组是否为空 22 | */ 23 | - (BOOL)cw_isEmpty; 24 | 25 | /** 26 | 3、新增某元素 27 | */ 28 | - (void)cw_push:(id)E; 29 | 30 | /** 31 | 4、新增某元素 32 | */ 33 | - (id)cw_pop; 34 | 35 | /** 36 | 5、新增某元素 37 | */ 38 | - (id)cw_top; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/CWStackList.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.m 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWStackList.h" 10 | 11 | @interface CWStackList() 12 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 13 | @end 14 | 15 | @implementation CWStackList 16 | 17 | - (instancetype)init{ 18 | if (self = [super init]) { 19 | self.array = [NSMutableArray array]; 20 | self.size = 0; 21 | } 22 | return self; 23 | } 24 | 25 | /** 26 | 1、数组的大小 27 | */ 28 | - (int)cw_size 29 | { 30 | return self.size; 31 | } 32 | 33 | /** 34 | 2、数组是否为空 35 | */ 36 | - (BOOL)cw_isEmpty 37 | { 38 | return self.size == 0; 39 | } 40 | 41 | /** 42 | 3、新增某元素 43 | */ 44 | - (void)cw_push:(id)E 45 | { 46 | [self.array addObject:E]; 47 | self.size++; 48 | } 49 | 50 | /** 51 | 4、新增某元素 52 | */ 53 | - (id)cw_pop 54 | { 55 | id object = self.array[self.size-1]; 56 | [self.array removeObjectAtIndex:self.size-1]; 57 | self.size--; 58 | return object; 59 | } 60 | 61 | /** 62 | 5、新增某元素 63 | */ 64 | - (id)cw_top 65 | { 66 | id object = self.array[self.size-1]; 67 | return object; 68 | } 69 | 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/Dijkstra算法参考图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinShortPathAlgorithms/01-最短路径/01-最短路径/Dijkstra算法参考图.png -------------------------------------------------------------------------------- /Algorithms/MinShortPathAlgorithms/README.md: -------------------------------------------------------------------------------- 1 | # Algorithms-and-Structures 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/00-拓扑排序/MinTreeAlgorithms.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/00-拓扑排序/MinTreeAlgorithms.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/00-拓扑排序/MinTreeAlgorithms/CWQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 队列特点:只能在队列尾添加、队列头删除元素 13 | **/ 14 | 15 | @interface CWQueueList : NSObject 16 | 17 | /**< 链表子节点数目 */ 18 | @property (nonatomic,assign) int size; 19 | /**< 队列元素 */ 20 | @property (nonatomic,copy) id ele; 21 | 22 | /** 23 | 1、入队(队尾入) 24 | */ 25 | - (void)cw_enQueue:(id)E; 26 | 27 | /** 28 | 2、出队(队头出) 29 | */ 30 | - (id)cw_deQueue; 31 | 32 | /** 33 | 3、出队(队头元素) 34 | */ 35 | - (id)cw_topQueue; 36 | 37 | /** 38 | 4、队列的大小 39 | */ 40 | - (int)cw_size; 41 | 42 | /** 43 | 5、队列是否为空 44 | */ 45 | - (BOOL)cw_isEmpty; 46 | 47 | /** 48 | 6、清空队列数据 49 | */ 50 | - (void)cw_clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/00-拓扑排序/MinTreeAlgorithms/CWStackList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.h 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWStackList : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 数组size */ 14 | 15 | /** 16 | 1、数组的大小 17 | */ 18 | - (int)cw_size; 19 | 20 | /** 21 | 2、数组是否为空 22 | */ 23 | - (BOOL)cw_isEmpty; 24 | 25 | /** 26 | 3、新增某元素 27 | */ 28 | - (void)cw_push:(id)E; 29 | 30 | /** 31 | 4、新增某元素 32 | */ 33 | - (id)cw_pop; 34 | 35 | /** 36 | 5、新增某元素 37 | */ 38 | - (id)cw_top; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/00-拓扑排序/MinTreeAlgorithms/CWStackList.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.m 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWStackList.h" 10 | 11 | @interface CWStackList() 12 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 13 | @end 14 | 15 | @implementation CWStackList 16 | 17 | - (instancetype)init{ 18 | if (self = [super init]) { 19 | self.array = [NSMutableArray array]; 20 | self.size = 0; 21 | } 22 | return self; 23 | } 24 | 25 | /** 26 | 1、数组的大小 27 | */ 28 | - (int)cw_size 29 | { 30 | return self.size; 31 | } 32 | 33 | /** 34 | 2、数组是否为空 35 | */ 36 | - (BOOL)cw_isEmpty 37 | { 38 | return self.size == 0; 39 | } 40 | 41 | /** 42 | 3、新增某元素 43 | */ 44 | - (void)cw_push:(id)E 45 | { 46 | [self.array addObject:E]; 47 | self.size++; 48 | } 49 | 50 | /** 51 | 4、新增某元素 52 | */ 53 | - (id)cw_pop 54 | { 55 | id object = self.array[self.size-1]; 56 | [self.array removeObjectAtIndex:self.size-1]; 57 | self.size--; 58 | return object; 59 | } 60 | 61 | /** 62 | 5、新增某元素 63 | */ 64 | - (id)cw_top 65 | { 66 | id object = self.array[self.size-1]; 67 | return object; 68 | } 69 | 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/00-拓扑排序/MinTreeAlgorithms/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // MinTreeAlgorithms 4 | // 5 | // Created by mac on 2019/10/21. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWGraph.h" 11 | 12 | 13 | 14 | // 1、拓扑排序 15 | void topologicalSort () 16 | { 17 | 18 | CWGraph *graph1 = [[CWGraph alloc] init]; 19 | // A -> B 20 | [graph1 addEdgeFrom:@"A" to:@"B" value:@""]; 21 | // B -> C B -> E B -> E 22 | [graph1 addEdgeFrom:@"B" to:@"C" value:@""]; 23 | [graph1 addEdgeFrom:@"B" to:@"D" value:@""]; 24 | [graph1 addEdgeFrom:@"B" to:@"E" value:@""]; 25 | // C -> E D -> E 26 | [graph1 addEdgeFrom:@"C" to:@"E" value:@""]; 27 | [graph1 addEdgeFrom:@"D" to:@"E" value:@""]; 28 | // E -> F 29 | [graph1 addEdgeFrom:@"E" to:@"F" value:@""]; 30 | 31 | // NSLog(@"%@",graph1); 32 | // 打印数据 33 | [graph1 topologicalSort:@"A"]; 34 | NSLog(@"=============="); 35 | 36 | } 37 | 38 | int main(int argc, const char * argv[]) { 39 | @autoreleasepool { 40 | 41 | topologicalSort(); 42 | 43 | 44 | 45 | 46 | } 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/CWBinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWBinaryHeap.h 3 | // 01-Kruskal算法(最小生成树) 4 | // 5 | // Created by 程金伟 on 2019/10/22. 6 | // Copyright © 2019 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWGraph.h" 11 | 12 | 13 | @interface CWBinaryHeap : NSObject 14 | 15 | @property (nonatomic,assign) int size; 16 | @property (nonatomic,strong) NSMutableArray *binaryHeaps; 17 | @property (nonatomic,assign) BOOL MaxHeap; 18 | 19 | /** 20 | 0、批量建堆 21 | */ 22 | - (void)batchHeaps:(NSArray *)array; 23 | /** 24 | 1、二叉堆的size 25 | */ 26 | - (int)heap_size; 27 | 28 | /** 29 | 2、二叉堆是否为空 30 | */ 31 | - (BOOL)isEmpty; 32 | 33 | /** 34 | 3、二叉堆的清空 35 | */ 36 | - (void)clear; 37 | 38 | /** 39 | 4、二叉堆添加元素 40 | */ 41 | - (void)addEle:(id)ele; 42 | 43 | /** 44 | 5、获取堆顶元素 45 | */ 46 | - (id)getTop; 47 | 48 | /** 49 | 6、删除堆顶元素 50 | */ 51 | - (id)removeTop; 52 | 53 | /** 54 | 7、删除堆顶元素同时插入一个新元素 55 | */ 56 | - (id)replaceTopWithEle:(id)ele; 57 | 58 | @end 59 | 60 | 61 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/CWGoodUnionFind.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWGoodUnionFind.h 3 | // 16-并查集(UnionFind) 4 | // 5 | // Created by 程金伟 on 2019/10/19. 6 | // Copyright © 2019 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | @class CWItem; 11 | @interface CWGoodUnionFind : NSObject 12 | @property (nonatomic,assign) int count; 13 | @property (nonatomic,strong) NSMutableDictionary *dicItems; 14 | // 初始化配置 15 | - (instancetype)initWithSetCount:(NSArray *)array; 16 | // 1、并查集的效率较好的实现方法(基于路径减半方法) 17 | - (CWItem *)findSet:(NSString *)value; 18 | - (void)unionSet:(NSString *)value1 value2:(NSString *)value2; 19 | - (BOOL)isSameSet:(NSString *)value1 value2:(NSString *)value2; 20 | 21 | @end 22 | 23 | 24 | @interface CWItem:NSObject 25 | // 可以考虑使用数组,但是进行赋值的时候需要对index进行特殊处理,不能覆盖。 26 | @property(nonatomic,strong)CWItem *parent; 27 | @property(nonatomic,copy)NSString *value; 28 | @property(nonatomic,copy)NSString *key; 29 | @property(nonatomic,assign)NSInteger rank; 30 | @property(nonatomic,copy)NSString *name; 31 | @end 32 | 33 | 34 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/CWQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 队列特点:只能在队列尾添加、队列头删除元素 13 | **/ 14 | 15 | @interface CWQueueList : NSObject 16 | 17 | /**< 链表子节点数目 */ 18 | @property (nonatomic,assign) int size; 19 | /**< 队列元素 */ 20 | @property (nonatomic,copy) id ele; 21 | 22 | /** 23 | 1、入队(队尾入) 24 | */ 25 | - (void)cw_enQueue:(id)E; 26 | 27 | /** 28 | 2、出队(队头出) 29 | */ 30 | - (id)cw_deQueue; 31 | 32 | /** 33 | 3、出队(队头元素) 34 | */ 35 | - (id)cw_topQueue; 36 | 37 | /** 38 | 4、队列的大小 39 | */ 40 | - (int)cw_size; 41 | 42 | /** 43 | 5、队列是否为空 44 | */ 45 | - (BOOL)cw_isEmpty; 46 | 47 | /** 48 | 6、清空队列数据 49 | */ 50 | - (void)cw_clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/CWStackList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.h 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWStackList : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 数组size */ 14 | 15 | /** 16 | 1、数组的大小 17 | */ 18 | - (int)cw_size; 19 | 20 | /** 21 | 2、数组是否为空 22 | */ 23 | - (BOOL)cw_isEmpty; 24 | 25 | /** 26 | 3、新增某元素 27 | */ 28 | - (void)cw_push:(id)E; 29 | 30 | /** 31 | 4、新增某元素 32 | */ 33 | - (id)cw_pop; 34 | 35 | /** 36 | 5、新增某元素 37 | */ 38 | - (id)cw_top; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/CWStackList.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.m 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWStackList.h" 10 | 11 | @interface CWStackList() 12 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 13 | @end 14 | 15 | @implementation CWStackList 16 | 17 | - (instancetype)init{ 18 | if (self = [super init]) { 19 | self.array = [NSMutableArray array]; 20 | self.size = 0; 21 | } 22 | return self; 23 | } 24 | 25 | /** 26 | 1、数组的大小 27 | */ 28 | - (int)cw_size 29 | { 30 | return self.size; 31 | } 32 | 33 | /** 34 | 2、数组是否为空 35 | */ 36 | - (BOOL)cw_isEmpty 37 | { 38 | return self.size == 0; 39 | } 40 | 41 | /** 42 | 3、新增某元素 43 | */ 44 | - (void)cw_push:(id)E 45 | { 46 | [self.array addObject:E]; 47 | self.size++; 48 | } 49 | 50 | /** 51 | 4、新增某元素 52 | */ 53 | - (id)cw_pop 54 | { 55 | id object = self.array[self.size-1]; 56 | [self.array removeObjectAtIndex:self.size-1]; 57 | self.size--; 58 | return object; 59 | } 60 | 61 | /** 62 | 5、新增某元素 63 | */ 64 | - (id)cw_top 65 | { 66 | id object = self.array[self.size-1]; 67 | return object; 68 | } 69 | 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/参考图片1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/参考图片1.png -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/参考图片2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinTreeAlgorithms/01-Kruskal算法(最小生成树)/01-Kruskal算法(最小生成树)/参考图片2.png -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/CWBinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWBinaryHeap.h 3 | // 01-Kruskal算法(最小生成树) 4 | // 5 | // Created by 程金伟 on 2019/10/22. 6 | // Copyright © 2019 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWGraph.h" 11 | 12 | 13 | @interface CWBinaryHeap : NSObject 14 | 15 | @property (nonatomic,assign) int size; 16 | @property (nonatomic,strong) NSMutableArray *binaryHeaps; 17 | @property (nonatomic,assign) BOOL MaxHeap; 18 | 19 | /** 20 | 0、批量建堆 21 | */ 22 | - (void)batchHeaps:(NSArray *)array; 23 | /** 24 | 1、二叉堆的size 25 | */ 26 | - (int)heap_size; 27 | 28 | /** 29 | 2、二叉堆是否为空 30 | */ 31 | - (BOOL)isEmpty; 32 | 33 | /** 34 | 3、二叉堆的清空 35 | */ 36 | - (void)clear; 37 | 38 | /** 39 | 4、二叉堆添加元素 40 | */ 41 | - (void)addEle:(id)ele; 42 | 43 | /** 44 | 5、获取堆顶元素 45 | */ 46 | - (id)getTop; 47 | 48 | /** 49 | 6、删除堆顶元素 50 | */ 51 | - (id)removeTop; 52 | 53 | /** 54 | 7、删除堆顶元素同时插入一个新元素 55 | */ 56 | - (id)replaceTopWithEle:(id)ele; 57 | 58 | @end 59 | 60 | 61 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/CWGoodUnionFind.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWGoodUnionFind.h 3 | // 16-并查集(UnionFind) 4 | // 5 | // Created by 程金伟 on 2019/10/19. 6 | // Copyright © 2019 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | @class CWItem; 11 | @interface CWGoodUnionFind : NSObject 12 | @property (nonatomic,assign) int count; 13 | @property (nonatomic,strong) NSMutableDictionary *dicItems; 14 | // 初始化配置 15 | - (instancetype)initWithSetCount:(NSArray *)array; 16 | // 1、并查集的效率较好的实现方法(基于路径减半方法) 17 | - (CWItem *)findSet:(NSString *)value; 18 | - (void)unionSet:(NSString *)value1 value2:(NSString *)value2; 19 | - (BOOL)isSameSet:(NSString *)value1 value2:(NSString *)value2; 20 | 21 | @end 22 | 23 | 24 | @interface CWItem:NSObject 25 | // 可以考虑使用数组,但是进行赋值的时候需要对index进行特殊处理,不能覆盖。 26 | @property(nonatomic,strong)CWItem *parent; 27 | @property(nonatomic,copy)NSString *value; 28 | @property(nonatomic,copy)NSString *key; 29 | @property(nonatomic,assign)NSInteger rank; 30 | @property(nonatomic,copy)NSString *name; 31 | @end 32 | 33 | 34 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/CWQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 队列特点:只能在队列尾添加、队列头删除元素 13 | **/ 14 | 15 | @interface CWQueueList : NSObject 16 | 17 | /**< 链表子节点数目 */ 18 | @property (nonatomic,assign) int size; 19 | /**< 队列元素 */ 20 | @property (nonatomic,copy) id ele; 21 | 22 | /** 23 | 1、入队(队尾入) 24 | */ 25 | - (void)cw_enQueue:(id)E; 26 | 27 | /** 28 | 2、出队(队头出) 29 | */ 30 | - (id)cw_deQueue; 31 | 32 | /** 33 | 3、出队(队头元素) 34 | */ 35 | - (id)cw_topQueue; 36 | 37 | /** 38 | 4、队列的大小 39 | */ 40 | - (int)cw_size; 41 | 42 | /** 43 | 5、队列是否为空 44 | */ 45 | - (BOOL)cw_isEmpty; 46 | 47 | /** 48 | 6、清空队列数据 49 | */ 50 | - (void)cw_clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/CWStackList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.h 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWStackList : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 数组size */ 14 | 15 | /** 16 | 1、数组的大小 17 | */ 18 | - (int)cw_size; 19 | 20 | /** 21 | 2、数组是否为空 22 | */ 23 | - (BOOL)cw_isEmpty; 24 | 25 | /** 26 | 3、新增某元素 27 | */ 28 | - (void)cw_push:(id)E; 29 | 30 | /** 31 | 4、新增某元素 32 | */ 33 | - (id)cw_pop; 34 | 35 | /** 36 | 5、新增某元素 37 | */ 38 | - (id)cw_top; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/CWStackList.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.m 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWStackList.h" 10 | 11 | @interface CWStackList() 12 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 13 | @end 14 | 15 | @implementation CWStackList 16 | 17 | - (instancetype)init{ 18 | if (self = [super init]) { 19 | self.array = [NSMutableArray array]; 20 | self.size = 0; 21 | } 22 | return self; 23 | } 24 | 25 | /** 26 | 1、数组的大小 27 | */ 28 | - (int)cw_size 29 | { 30 | return self.size; 31 | } 32 | 33 | /** 34 | 2、数组是否为空 35 | */ 36 | - (BOOL)cw_isEmpty 37 | { 38 | return self.size == 0; 39 | } 40 | 41 | /** 42 | 3、新增某元素 43 | */ 44 | - (void)cw_push:(id)E 45 | { 46 | [self.array addObject:E]; 47 | self.size++; 48 | } 49 | 50 | /** 51 | 4、新增某元素 52 | */ 53 | - (id)cw_pop 54 | { 55 | id object = self.array[self.size-1]; 56 | [self.array removeObjectAtIndex:self.size-1]; 57 | self.size--; 58 | return object; 59 | } 60 | 61 | /** 62 | 5、新增某元素 63 | */ 64 | - (id)cw_top 65 | { 66 | id object = self.array[self.size-1]; 67 | return object; 68 | } 69 | 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/参考图片1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/参考图片1-1.png -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/参考图片1-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/参考图片1-2.png -------------------------------------------------------------------------------- /Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/参考图片2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/MinTreeAlgorithms/02-Prim算法(最小生成树)/02-Prim算法(最小生成树)/参考图片2.png -------------------------------------------------------------------------------- /Algorithms/NumsQueue(回溯)/NumsQueue(回溯).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/NumsQueue(回溯)/NumsQueue(回溯).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/NumsQueue(回溯)/NumsQueue(回溯)/CWNumsQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWNumsQueue.h 3 | // NumsQueue(回溯) 4 | // 5 | // Created by mac on 2019/11/13. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWNumsQueue : NSObject 12 | 13 | // 1、初始化 14 | - (instancetype)initWithNumber:(int)number; 15 | // 2、计算皇后总方法 16 | - (void)placeQueues; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Algorithms/NumsQueue(回溯)/NumsQueue(回溯)/CWNumsQueue2.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWNumsQueue2.h 3 | // NumsQueue(回溯) 4 | // 5 | // Created by mac on 2019/11/13. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWNumsQueue2 : NSObject 12 | 13 | // 1、初始化 14 | - (instancetype)initWithNumber:(int)number; 15 | // 2、计算皇后总方法 16 | - (void)placeQueues; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Algorithms/NumsQueue(回溯)/NumsQueue(回溯)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // NumsQueue(回溯) 4 | // 5 | // Created by mac on 2019/11/13. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWNumsQueue.h" 11 | #import "CWNumsQueue2.h" 12 | int main(int argc, const char * argv[]) { 13 | @autoreleasepool { 14 | 15 | // 皇后1方法 16 | // CWNumsQueue *queue = [[CWNumsQueue alloc] initWithNumber:4]; 17 | // [queue placeQueues]; 18 | // 19 | // 皇后2方法 20 | CWNumsQueue2 *queue2 = [[CWNumsQueue2 alloc] initWithNumber:4]; 21 | [queue2 placeQueues]; 22 | 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Algorithms/Recursive/Recursive.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/Recursive/Recursive.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/Recursive/Recursive/CWRecursive.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWRecursive.h 3 | // Recursive 4 | // 5 | // Created by 程金伟 on 2019/11/7. 6 | // Copyright © 2019 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface CWRecursive : NSObject 14 | 15 | // 1、上楼梯 16 | - (int)climbStair:(int)num; 17 | 18 | - (int)good_climbStair:(int)num; 19 | 20 | 21 | // 2、汉诺塔 22 | - (void)hanoi:(int)num A:(NSString *)A B:(NSString *)B C:(NSString *)C; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Algorithms/Recursive/Recursive/CWRecursive.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWRecursive.m 3 | // Recursive 4 | // 5 | // Created by 程金伟 on 2019/11/7. 6 | // Copyright © 2019 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWRecursive.h" 10 | 11 | @implementation CWRecursive 12 | 13 | // 1、上楼梯 14 | - (int)climbStair:(int)num 15 | { 16 | if (num <= 2) { 17 | return num; 18 | } 19 | return [self climbStair:num-1] + [self climbStair:num-2]; 20 | } 21 | 22 | - (int)good_climbStair:(int)num 23 | { 24 | if(num <= 2)return num; 25 | int first = 1; 26 | int second = 2; 27 | for (int i = 3; i <= 4; i++) { 28 | second = first + second; 29 | first = second - first; 30 | } 31 | return second; 32 | } 33 | 34 | // 2、汉诺塔 35 | - (void)hanoi:(int)num A:(NSString *)A B:(NSString *)B C:(NSString *)C 36 | { 37 | if(num <= 1) { 38 | [self move:num from:A to:C]; 39 | } 40 | [self hanoi:num - 1 A:A B:C C:B]; 41 | [self move:num from:A to:C]; 42 | [self hanoi:num - 1 A:B B:A C:C]; 43 | } 44 | 45 | - (void)move:(int)num from:(NSString *)from to:(NSString *)to 46 | { 47 | NSLog(@"盘号:%d + %@ -> %@",num,from,to); 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /Algorithms/Recursive/Recursive/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Recursive 4 | // 5 | // Created by 程金伟 on 2019/11/7. 6 | // Copyright © 2019 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWRecursive.h" 11 | int main(int argc, const char * argv[]) { 12 | @autoreleasepool { 13 | CWRecursive *recursive = [[CWRecursive alloc] init]; 14 | 15 | NSLog(@"%d-%d",[recursive climbStair:4],[recursive good_climbStair:4]); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/00-排序(Sort)/00-排序(Sort).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/00-排序(Sort)/00-排序(Sort).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/00-排序(Sort)/00-排序(Sort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/00-排序(Sort)/00-排序(Sort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/00-排序(Sort)/00-排序(Sort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 00-排序(Sort).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/00-排序(Sort)/00-排序(Sort)/CWMaxBinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWMaxBinaryHeap.h 3 | // 14-二叉堆(BinaryHeap) 4 | // 5 | // Created by mac on 2019/6/21. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWMaxBinaryHeap : NSObject 12 | 13 | @property (nonatomic,assign) int size; 14 | @property (nonatomic,strong) NSMutableArray *binaryHeaps; 15 | @property (nonatomic,assign) BOOL MaxHeap; 16 | 17 | /** 18 | 0、批量建堆 19 | */ 20 | - (void)batchHeaps:(NSArray *)array; 21 | - (void)batchOperation; 22 | - (void)afterRemove:(NSInteger)index; 23 | /** 24 | 1、二叉堆的size 25 | */ 26 | - (int)heap_size; 27 | 28 | /** 29 | 2、二叉堆是否为空 30 | */ 31 | - (BOOL)isEmpty; 32 | 33 | /** 34 | 3、二叉堆的清空 35 | */ 36 | - (void)clear; 37 | 38 | /** 39 | 4、二叉堆添加元素 40 | */ 41 | - (void)addEle:(id)ele; 42 | 43 | /** 44 | 5、获取堆顶元素 45 | */ 46 | - (id)getTop; 47 | 48 | /** 49 | 6、删除堆顶元素 50 | */ 51 | - (id)removeTop; 52 | 53 | /** 54 | 7、删除堆顶元素同时插入一个新元素 55 | */ 56 | - (id)replaceTopWithEle:(id)ele; 57 | 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/00-排序(Sort)/00-排序(Sort)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 01-冒泡排序.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 01-冒泡排序.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/01-冒泡排序(Bubble Sort)/01-冒泡排序/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 01-SelectSort.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 01-SelectSort.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 01-SelectSort.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort/CWMaxBinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWMaxBinaryHeap.h 3 | // 14-二叉堆(BinaryHeap) 4 | // 5 | // Created by mac on 2019/6/21. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWMaxBinaryHeap : NSObject 12 | 13 | @property (nonatomic,assign) int size; 14 | @property (nonatomic,strong) NSMutableArray *binaryHeaps; 15 | @property (nonatomic,assign) BOOL MaxHeap; 16 | 17 | /** 18 | 0、批量建堆 19 | */ 20 | - (void)batchHeaps:(NSArray *)array; 21 | - (void)batchOperation; 22 | - (void)afterRemove:(NSInteger)index; 23 | /** 24 | 1、二叉堆的size 25 | */ 26 | - (int)heap_size; 27 | 28 | /** 29 | 2、二叉堆是否为空 30 | */ 31 | - (BOOL)isEmpty; 32 | 33 | /** 34 | 3、二叉堆的清空 35 | */ 36 | - (void)clear; 37 | 38 | /** 39 | 4、二叉堆添加元素 40 | */ 41 | - (void)addEle:(id)ele; 42 | 43 | /** 44 | 5、获取堆顶元素 45 | */ 46 | - (id)getTop; 47 | 48 | /** 49 | 6、删除堆顶元素 50 | */ 51 | - (id)removeTop; 52 | 53 | /** 54 | 7、删除堆顶元素同时插入一个新元素 55 | */ 56 | - (id)replaceTopWithEle:(id)ele; 57 | 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/02-选择排序(Selection Sort)/01-SelectSort/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03-插入排序(Insert).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 03-插入排序(Insert).xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03-插入排序(Insert).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/03-插入排序(Insert Sort)/03-插入排序(Insert)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/04-归并排序(Merge Sort)/04-归并排序(Merge Sort).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/04-归并排序(Merge Sort)/04-归并排序(Merge Sort).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/04-归并排序(Merge Sort)/04-归并排序(Merge Sort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/04-归并排序(Merge Sort)/04-归并排序(Merge Sort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/04-归并排序(Merge Sort)/04-归并排序(Merge Sort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/04-归并排序(Merge Sort)/04-归并排序(Merge Sort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 04-归并排序(Merge Sort).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 04-归并排序(Merge Sort).xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/04-归并排序(Merge Sort)/04-归并排序(Merge Sort)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/05-快速排序(QuickSort)/05-快速排序(QuickSort).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/05-快速排序(QuickSort)/05-快速排序(QuickSort).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/05-快速排序(QuickSort)/05-快速排序(QuickSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/05-快速排序(QuickSort)/05-快速排序(QuickSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/05-快速排序(QuickSort)/05-快速排序(QuickSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/05-快速排序(QuickSort)/05-快速排序(QuickSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 05-快速排序(QuickSort).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/05-快速排序(QuickSort)/05-快速排序(QuickSort)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/06-希尔排序(ShellSort)/06-希尔排序(ShellSort).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/06-希尔排序(ShellSort)/06-希尔排序(ShellSort).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/06-希尔排序(ShellSort)/06-希尔排序(ShellSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/06-希尔排序(ShellSort)/06-希尔排序(ShellSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/06-希尔排序(ShellSort)/06-希尔排序(ShellSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/06-希尔排序(ShellSort)/06-希尔排序(ShellSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 06-希尔排序(ShellSort).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/06-希尔排序(ShellSort)/06-希尔排序(ShellSort)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/07-计数排序(CountingSort)/07-计数排序(CountingSort).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/07-计数排序(CountingSort)/07-计数排序(CountingSort).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/07-计数排序(CountingSort)/07-计数排序(CountingSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/07-计数排序(CountingSort)/07-计数排序(CountingSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/07-计数排序(CountingSort)/07-计数排序(CountingSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/07-计数排序(CountingSort)/07-计数排序(CountingSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 07-计数排序(CountingSort).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/07-计数排序(CountingSort)/07-计数排序(CountingSort)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 08-基数排序(RedixSort).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 08-基数排序(RedixSort).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/08-基数排序(RedixSort)/08-基数排序(RedixSort)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/09-桶排序(BucketSort)/09-桶排序(BucketSort).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/09-桶排序(BucketSort)/09-桶排序(BucketSort).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/09-桶排序(BucketSort)/09-桶排序(BucketSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/09-桶排序(BucketSort)/09-桶排序(BucketSort).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/09-桶排序(BucketSort)/09-桶排序(BucketSort).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 09-桶排序(BucketSort).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/09-桶排序(BucketSort)/09-桶排序(BucketSort)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | // 2、判断是否为降序数组 19 | + (BOOL)isDescOrderArray:(NSArray *)array; 20 | // 3、判断是否为正序数组 21 | + (BOOL)isAscOrderArray:(NSArray *)array; 22 | // 4、比较方法 23 | - (BOOL)compare:(NSString *)value1 value2:(NSString *)value2; 24 | // 5、交换次数 25 | - (void)exchangeValue; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/Resource/BubbleSortResult.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/Resource/BubbleSortResult.jpg -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/Resource/InsertSortResult.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/Resource/InsertSortResult.jpg -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/Resource/MergeSortResult.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/Resource/MergeSortResult.jpg -------------------------------------------------------------------------------- /Algorithms/SortAlgorithms/Resource/SelectSortResult.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Algorithms/SortAlgorithms/Resource/SelectSortResult.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algorithms-and-Structures 2 | 3 | > ## 一、数据结构(Structures) 4 | > * 1、复杂度。 5 | > * 2、动态数组(Dynamic)。 6 | > * 3、链表。 7 | > * 4、双向链表。 8 | > * 5、循环链表。 9 | > * 6、栈。 10 | > * 7、队列。 11 | > * 8、二叉搜索树。 12 | > * 9、AVL平衡树。 13 | > * 10、RBT红黑树(RedBlackTree) 。 14 | > * 11、集合(Set)。 15 | > * 12、映射(Map)。 16 | > * 13、哈希值(hash)。 17 | > * 14、二叉堆(BinaryHeap)。 18 | > * 15、优先级队列(Priority Queue)。 19 | > * 16、前缀树(Trie)。 20 | > * 17、并查集(UnionFind)。 21 | > * 18、图(Graph)。 22 | 23 | > ## 二、算法(Algorithms) 24 | > * 2-1、排序 25 | > * 冒泡排序(Bubble Sort) 26 | > * 选择排序(Selection Sort) 27 | > * 堆排序(Selection Sort) 28 | > * 插入排序(Insert Sort) 29 | > * 归并排序(Merge Sort) 30 | > * 快速排序(Quick Sort) 31 | > * 希尔排序(Shell Sort) 32 | > * 计数排序(CountingSort) 33 | > * 基数排序(RedixSort) 34 | > * 桶排序(BucketSort) 35 | > * 2-2、最小生成树、最短路径算法 36 | > * 拓扑排序算法 37 | > * 最小生成树 38 | > * Kruskal算法 39 | > * Prim算法 40 | > * 最短路径 41 | > * Dijkstra算法 42 | > * Bellman-Ford算法 43 | > * Floyd算法 44 | > * 2-3、递归(Recursive) 45 | > * 2-4、回溯(Backtrack) 46 | > * 2-5、贪心策略(Greedy) 47 | > * 2-6、分治(DivideAndConquer) 48 | > * 2-7、串算法 49 | > * KMP算法(待更新) 50 | > * Boyer-Moore算法(待更新) 51 | > * Karp-Rabin算法(待更新) 52 | > * Sunday算法(待更新.) 53 | > * 更新中... 54 | 55 | 持续更新中... 56 | ---------- 57 | 58 | 59 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/01-复杂度/01-复杂度.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 01-复杂度.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度/CWFibObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWFibObject.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /**< 斐波那契数列 */ 12 | @interface CWFibObject : NSObject 13 | 14 | /** 15 | 1、常规递归的斐波那契计算方法 16 | @param value 第几个斐波那契数列 17 | */ 18 | - (int)fib_recursive:(int)value; 19 | 20 | 21 | /** 22 | 2、优化的斐波那契计算方法 23 | @param value 第几个斐波那契数列 24 | */ 25 | - (int)fib_good:(int)value; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度/CWFibObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWFibObject.m 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWFibObject.h" 10 | 11 | @implementation CWFibObject 12 | 13 | - (int)fib_recursive:(int)value 14 | { 15 | if (value <= 2) return value; 16 | int sum = [self fib_recursive:value-1] + [self fib_recursive:value-2]; 17 | return sum; 18 | 19 | } 20 | 21 | - (int)fib_good:(int)value 22 | { 23 | if (value <= 2) return value; 24 | int sum = 2,first = 1,secend = 1; 25 | for (int i = 3; i < value; i++) { 26 | first = secend; 27 | secend = sum; 28 | sum = first + secend; 29 | } 30 | return sum; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | /**< block */ 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | /**< 执行任务消耗的时间( task consume )*/ 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | 17 | @property (nonatomic,copy) ExecuteBlock block; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Structures/01-复杂度/01-复杂度/CWTimeTool.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.m 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWTimeTool.h" 10 | 11 | @implementation CWTimeTool 12 | 13 | - (void)executeTimesForFunction:(ExecuteBlock)block 14 | { 15 | 16 | _block = block; 17 | if (_block) { 18 | // 1、开始时间 19 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 20 | NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"]; 21 | [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss SSS"]; 22 | [formatter setTimeZone:timeZone]; 23 | NSDate *dateS = [NSDate date]; 24 | NSString *tempS = [formatter stringFromDate:dateS]; 25 | double timeS = (long)([dateS timeIntervalSince1970]*10000); 26 | 27 | // 2、task执行 28 | _block(); 29 | 30 | // 3、结束时间 31 | NSDate *dateE = [NSDate date]; 32 | NSString *tempE = [formatter stringFromDate:dateE]; 33 | double timeE = (long)([dateE timeIntervalSince1970]*10000); 34 | 35 | // 4、耗时计算 36 | double consume = timeE - timeS; 37 | NSLog(@"\n [开始:%@]\n [结束:%@]\n [耗时:%.2fs]\n",tempS,tempE,consume/10000); 38 | } 39 | } 40 | 41 | @end 42 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 02-动态数组(Dynamic).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 02-动态数组(Dynamic).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic)/CWArrayList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWArrayList.h 3 | // 02-动态数组 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /**模拟动态数组的内部实现: 12 | 1、基于array操作 13 | 2、扩容1.5倍 14 | 3、降容1.5倍 15 | **/ 16 | 17 | @interface CWArrayList : NSObject 18 | @property (nonatomic,assign) int size; /**< 数组size */ 19 | @property (nonatomic,assign) int capacity; /**< 数组的内存大小 */ 20 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 21 | 22 | /** 23 | 1、清空数据数据 24 | */ 25 | - (void)cw_clear; 26 | 27 | /** 28 | 2、数组的大小 29 | */ 30 | - (int)cw_size; 31 | 32 | /** 33 | 3、数组是否为空 34 | */ 35 | - (BOOL)cw_isEmpty; 36 | 37 | /** 38 | 4、是否包含某元素 39 | */ 40 | - (BOOL)cw_isContainE:(id)E; 41 | 42 | /** 43 | 5、根据下标查找某元素 44 | */ 45 | - (id)cw_getIndex:(int)index; 46 | 47 | /** 48 | 6、根据下标设置某元素 49 | */ 50 | - (id)cw_setE:(int)index E:(id)E; 51 | 52 | /** 53 | 7、新增某元素 54 | */ 55 | - (void)cw_addE:(id)E; 56 | 57 | /** 58 | 8、新增某个index下新增元素 59 | */ 60 | - (void)cw_addE:(id)E index:(int)index; 61 | 62 | /** 63 | 9、移除index元素 64 | */ 65 | - (id)cw_removeIndex:(int)index; 66 | 67 | 68 | /** 69 | 10、移除index元素 70 | */ 71 | - (id)cw_removeE:(id)E; 72 | 73 | /** 74 | 11、根据元素查找下标 75 | */ 76 | - (int)cw_indexOf:(id)E; 77 | 78 | 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic)/CWArrayListEModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWArrayListEModel.h 3 | // 02-动态数组(Dynamic) 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWArrayListEModel : NSObject 12 | 13 | @property (nonatomic,copy) NSString *name; /**< name */ 14 | @property (nonatomic,assign) NSInteger age; /**< age */ 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Structures/02-动态数组(Dynamic)/02-动态数组(Dynamic)/CWArrayListEModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWArrayListEModel.m 3 | // 02-动态数组(Dynamic) 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWArrayListEModel.h" 10 | 11 | @implementation CWArrayListEModel 12 | 13 | -(NSString *)description 14 | { 15 | return [NSString stringWithFormat:@"age:%ld name:%@",_age,_name]; 16 | } 17 | 18 | - (void)dealloc 19 | { 20 | NSLog(@"Model-dealloc"); 21 | } 22 | @end 23 | -------------------------------------------------------------------------------- /Structures/03-链表/03-链表.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/03-链表/03-链表.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/03-链表/03-链表.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/03-链表/03-链表.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/03-链表/03-链表.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/03-链表/03-链表.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/03-链表/03-链表.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03-链表.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/03-链表/03-链表.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/03-链表/03-链表.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03-链表.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/03-链表/03-链表/CWListNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWListNode.h 3 | // 03-链表 4 | // 5 | // Created by mac on 2019/5/10. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWListNode : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 链表子节点数目 */ 14 | 15 | /** 16 | 1、新增某元素 17 | */ 18 | - (void)cw_addE:(id)E; 19 | 20 | /** 21 | 2、新增某个index下新增元素 22 | */ 23 | - (void)cw_addE:(id)E index:(int)index; 24 | 25 | /** 26 | 3、移除index元素 27 | */ 28 | - (id)cw_removeIndex:(int)index; 29 | 30 | /** 31 | 4、移除index元素 32 | */ 33 | - (id)cw_removeE:(id)E; 34 | 35 | /** 36 | 5、根据元素查找下标 37 | */ 38 | - (int)cw_indexOf:(id)E; 39 | 40 | /** 41 | 6、清空数据数据 42 | */ 43 | - (void)cw_clear; 44 | 45 | /** 46 | 7、数组的大小 47 | */ 48 | - (int)cw_size; 49 | 50 | /** 51 | 8、数组是否为空 52 | */ 53 | - (BOOL)cw_isEmpty; 54 | 55 | /** 56 | 9、是否包含某元素 57 | */ 58 | - (BOOL)cw_isContainE:(id)E; 59 | 60 | /** 61 | 10、根据下标查找某元素 62 | */ 63 | - (id)cw_getIndex:(int)index; 64 | 65 | 66 | /** 67 | 11、反转链表 68 | */ 69 | - (CWListNode *)cw_reverseListNode:(CWListNode *)head; 70 | 71 | 72 | 73 | 74 | 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/04-双向链表/04-双向链表.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/04-双向链表/04-双向链表.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 04-双向链表.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 04-双向链表.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表/CWListNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWListNode.h 3 | // 03-链表 4 | // 5 | // Created by mac on 2019/5/10. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWListNode : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 链表子节点数目 */ 14 | 15 | /** 16 | 1、新增某元素 17 | */ 18 | - (void)cw_addE:(id)E; 19 | 20 | /** 21 | 2、新增某个index下新增元素 22 | */ 23 | - (void)cw_addE:(id)E index:(int)index; 24 | 25 | /** 26 | 3、移除index元素 27 | */ 28 | - (id)cw_removeIndex:(int)index; 29 | 30 | /** 31 | 4、移除index元素 32 | */ 33 | - (id)cw_removeE:(id)E; 34 | 35 | /** 36 | 5、根据元素查找下标 37 | */ 38 | - (int)cw_indexOf:(id)E; 39 | 40 | /** 41 | 6、清空数据数据 42 | */ 43 | - (void)cw_clear; 44 | 45 | /** 46 | 7、数组的大小 47 | */ 48 | - (int)cw_size; 49 | 50 | /** 51 | 8、数组是否为空 52 | */ 53 | - (BOOL)cw_isEmpty; 54 | 55 | /** 56 | 9、是否包含某元素 57 | */ 58 | - (BOOL)cw_isContainE:(id)E; 59 | 60 | /** 61 | 10、根据下标查找某元素 62 | */ 63 | - (id)cw_getIndex:(int)index; 64 | 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Structures/04-双向链表/04-双向链表/remark.md: -------------------------------------------------------------------------------- 1 | # 参考资料 2 | 3 | 4 | ####1、 5 | - (void)cw_addE:(id)E index:(int)index{ 6 | 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/05-循环链表/05-循环链表.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/05-循环链表/05-循环链表.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 05-循环链表.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 05-循环链表.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表/CWDoubleCycleNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWDoubleCycleNode.h 3 | // 05-循环链表 4 | // 5 | // Created by mac on 2019/5/13. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWDoubleCycleNode : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 链表子节点数目 */ 14 | 15 | /** 16 | 1、新增某元素 17 | */ 18 | - (void)cw_addE:(id)E; 19 | 20 | /** 21 | 2、新增某个index下新增元素 22 | */ 23 | - (void)cw_addE:(id)E index:(int)index; 24 | 25 | /** 26 | 3、移除index元素 27 | */ 28 | - (id)cw_removeIndex:(int)index; 29 | 30 | /** 31 | 4、移除index元素 32 | */ 33 | - (id)cw_removeE:(id)E; 34 | 35 | /** 36 | 5、根据元素查找下标 37 | */ 38 | - (int)cw_indexOf:(id)E; 39 | 40 | /** 41 | 6、清空数据数据 42 | */ 43 | - (void)cw_clear; 44 | 45 | /** 46 | 7、数组的大小 47 | */ 48 | - (int)cw_size; 49 | 50 | /** 51 | 8、数组是否为空 52 | */ 53 | - (BOOL)cw_isEmpty; 54 | 55 | /** 56 | 9、是否包含某元素 57 | */ 58 | - (BOOL)cw_isContainE:(id)E; 59 | 60 | /** 61 | 10、根据下标查找某元素 62 | */ 63 | - (id)cw_getIndex:(int)index; 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表/CWListNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWListNode.h 3 | // 03-链表 4 | // 5 | // Created by mac on 2019/5/10. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWListNode : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 链表子节点数目 */ 14 | 15 | /** 16 | 1、新增某元素 17 | */ 18 | - (void)cw_addE:(id)E; 19 | 20 | /** 21 | 2、新增某个index下新增元素 22 | */ 23 | - (void)cw_addE:(id)E index:(int)index; 24 | 25 | /** 26 | 3、移除index元素 27 | */ 28 | - (id)cw_removeIndex:(int)index; 29 | 30 | /** 31 | 4、移除index元素 32 | */ 33 | - (id)cw_removeE:(id)E; 34 | 35 | /** 36 | 5、根据元素查找下标 37 | */ 38 | - (int)cw_indexOf:(id)E; 39 | 40 | /** 41 | 6、清空数据数据 42 | */ 43 | - (void)cw_clear; 44 | 45 | /** 46 | 7、数组的大小 47 | */ 48 | - (int)cw_size; 49 | 50 | /** 51 | 8、数组是否为空 52 | */ 53 | - (BOOL)cw_isEmpty; 54 | 55 | /** 56 | 9、是否包含某元素 57 | */ 58 | - (BOOL)cw_isContainE:(id)E; 59 | 60 | /** 61 | 10、根据下标查找某元素 62 | */ 63 | - (id)cw_getIndex:(int)index; 64 | 65 | 66 | /** 67 | 11、反转链表 68 | */ 69 | - (CWListNode *)cw_reverseListNode:(CWListNode *)head; 70 | 71 | 72 | 73 | 74 | 75 | 76 | @end 77 | -------------------------------------------------------------------------------- /Structures/05-循环链表/05-循环链表/CWSingleCycleNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWSingleCycleNode.h 3 | // 05-循环链表 4 | // 5 | // Created by mac on 2019/5/13. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWSingleCycleNode : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 链表子节点数目 */ 14 | 15 | /** 16 | 1、新增某元素 17 | */ 18 | - (void)cw_addE:(id)E; 19 | 20 | /** 21 | 2、新增某个index下新增元素 22 | */ 23 | - (void)cw_addE:(id)E index:(int)index; 24 | 25 | /** 26 | 3、移除index元素 27 | */ 28 | - (id)cw_removeIndex:(int)index; 29 | 30 | /** 31 | 4、移除index元素 32 | */ 33 | - (id)cw_removeE:(id)E; 34 | 35 | /** 36 | 5、根据元素查找下标 37 | */ 38 | - (int)cw_indexOf:(id)E; 39 | 40 | /** 41 | 6、清空数据数据 42 | */ 43 | - (void)cw_clear; 44 | 45 | /** 46 | 7、数组的大小 47 | */ 48 | - (int)cw_size; 49 | 50 | /** 51 | 8、数组是否为空 52 | */ 53 | - (BOOL)cw_isEmpty; 54 | 55 | /** 56 | 9、是否包含某元素 57 | */ 58 | - (BOOL)cw_isContainE:(id)E; 59 | 60 | /** 61 | 10、根据下标查找某元素 62 | */ 63 | - (id)cw_getIndex:(int)index; 64 | 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/06-栈/06-栈.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/06-栈/06-栈.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 06-栈.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 06-栈.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈/CWStackList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.h 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWStackList : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 数组size */ 14 | 15 | /** 16 | 1、数组的大小 17 | */ 18 | - (int)cw_size; 19 | 20 | /** 21 | 2、数组是否为空 22 | */ 23 | - (BOOL)cw_isEmpty; 24 | 25 | /** 26 | 3、新增某元素 27 | */ 28 | - (void)cw_push:(id)E; 29 | 30 | /** 31 | 4、新增某元素 32 | */ 33 | - (id)cw_pop; 34 | 35 | /** 36 | 5、新增某元素 37 | */ 38 | - (id)cw_top; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Structures/06-栈/06-栈/CWStackList.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.m 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWStackList.h" 10 | 11 | @interface CWStackList() 12 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 13 | @end 14 | 15 | @implementation CWStackList 16 | 17 | - (instancetype)init{ 18 | if (self = [super init]) { 19 | self.array = [NSMutableArray array]; 20 | self.size = 0; 21 | } 22 | return self; 23 | } 24 | 25 | /** 26 | 1、数组的大小 27 | */ 28 | - (int)cw_size 29 | { 30 | return self.size; 31 | } 32 | 33 | /** 34 | 2、数组是否为空 35 | */ 36 | - (BOOL)cw_isEmpty 37 | { 38 | return self.size == 0; 39 | } 40 | 41 | /** 42 | 3、新增某元素 43 | */ 44 | - (void)cw_push:(id)E 45 | { 46 | [self.array addObject:E]; 47 | self.size++; 48 | } 49 | 50 | /** 51 | 4、新增某元素 52 | */ 53 | - (id)cw_pop 54 | { 55 | id object = self.array[self.size-1]; 56 | [self.array removeObjectAtIndex:self.size-1]; 57 | self.size--; 58 | return object; 59 | } 60 | 61 | /** 62 | 5、新增某元素 63 | */ 64 | - (id)cw_top 65 | { 66 | id object = self.array[self.size-1]; 67 | return object; 68 | } 69 | 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/07-队列/07-队列.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/07-队列/07-队列.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 07-队列.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列/CWCycleQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWCycleQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 循环队列:可以从尾添加,头删除的循环队列,内部基于数组实现功能。 13 | **/ 14 | @interface CWCycleQueueList : NSObject 15 | 16 | @property (nonatomic,assign) int size; /**< 数组size */ 17 | @property (nonatomic,assign) int front; /**< 指向队列的头部下标 */ 18 | @property (nonatomic,assign) int capacity; /**< 数组的内存大小 */ 19 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 20 | 21 | /** 22 | 1、入队(队尾入) 23 | */ 24 | - (void)cw_enQueue:(id)E; 25 | 26 | /** 27 | 2、出队(队头出) 28 | */ 29 | - (id)cw_deQueue; 30 | 31 | /** 32 | 3、出队(队头元素) 33 | */ 34 | - (id)cw_topQueue; 35 | 36 | /** 37 | 4、队列的大小 38 | */ 39 | - (int)cw_size; 40 | 41 | /** 42 | 5、队列是否为空 43 | */ 44 | - (BOOL)cw_isEmpty; 45 | 46 | /** 47 | 6、清空队列数据 48 | */ 49 | - (void)cw_clear; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列/CWDoubleCycleQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWDoubleCycleQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | /** 11 | 双端循环队列:可以从头尾添加,头尾删除的循环队列,内部基于数组实现功能。 12 | **/ 13 | 14 | @interface CWDoubleCycleQueueList : NSObject 15 | 16 | @property (nonatomic,assign) int size; /**< 数组size */ 17 | @property (nonatomic,assign) int front; /**< 指向队列的头部下标 */ 18 | @property (nonatomic,assign) int capacity; /**< 数组的内存大小 */ 19 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 20 | 21 | /** 22 | 1、入队(队头入) 23 | */ 24 | - (void)cw_enQueueHead:(id)E; 25 | 26 | /** 27 | 2、入队(队尾入) 28 | */ 29 | - (void)cw_enQueueTail:(id)E; 30 | 31 | /** 32 | 3、出队(队头出) 33 | */ 34 | - (id)cw_deQueueHead; 35 | 36 | /** 37 | 4、出队(队尾出) 38 | */ 39 | - (id)cw_deQueueTail; 40 | 41 | /** 42 | 5、获取队头元素 43 | */ 44 | - (id)cw_headQueue; 45 | 46 | /** 47 | 6、获取队尾元素 48 | */ 49 | - (id)cw_tailQueue; 50 | 51 | /** 52 | 7、队列的大小 53 | */ 54 | - (int)cw_size; 55 | 56 | /** 57 | 8、队列是否为空 58 | */ 59 | - (BOOL)cw_isEmpty; 60 | 61 | /** 62 | 9、清空队列数据 63 | */ 64 | - (void)cw_clear; 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列/CWDoubleQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWDoubleQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 双端队列特点:能在队列头尾二端添加、删除元素 13 | **/ 14 | 15 | @interface CWDoubleQueueList : NSObject 16 | 17 | /**< 链表子节点数目 */ 18 | @property (nonatomic,assign) int size; 19 | /**< 队列元素 */ 20 | @property (nonatomic,copy) id ele; 21 | 22 | /** 23 | 1、入队(队头入队) 24 | */ 25 | - (void)cw_enQueueH:(id)E; 26 | 27 | /** 28 | 2、入队(队尾入队) 29 | */ 30 | - (void)cw_enQueueT:(id)E; 31 | 32 | /** 33 | 3、出队(队头出队) 34 | */ 35 | - (id)cw_deQueueH; 36 | 37 | /** 38 | 4、出队(队尾出队) 39 | */ 40 | - (id)cw_deQueueT; 41 | 42 | /** 43 | 5、获取队列top元素(队尾元素) 44 | */ 45 | - (id)cw_tailQueue; 46 | 47 | /** 48 | 6、获取队列元素(队头元素) 49 | */ 50 | - (id)cw_headQueue; 51 | 52 | /** 53 | 7、队列的大小 54 | */ 55 | - (int)cw_size; 56 | 57 | /** 58 | 8、队列是否为空 59 | */ 60 | - (BOOL)cw_isEmpty; 61 | 62 | /** 63 | 9、清空队列数据 64 | */ 65 | - (void)cw_clear; 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Structures/07-队列/07-队列/CWQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 队列特点:只能在队列尾添加、队列头删除元素 13 | **/ 14 | 15 | @interface CWQueueList : NSObject 16 | 17 | /**< 链表子节点数目 */ 18 | @property (nonatomic,assign) int size; 19 | /**< 队列元素 */ 20 | @property (nonatomic,copy) id ele; 21 | 22 | /** 23 | 1、入队(队尾入) 24 | */ 25 | - (void)cw_enQueue:(id)E; 26 | 27 | /** 28 | 2、出队(队头出) 29 | */ 30 | - (id)cw_deQueue; 31 | 32 | /** 33 | 3、出队(队头元素) 34 | */ 35 | - (id)cw_topQueue; 36 | 37 | /** 38 | 4、队列的大小 39 | */ 40 | - (int)cw_size; 41 | 42 | /** 43 | 5、队列是否为空 44 | */ 45 | - (BOOL)cw_isEmpty; 46 | 47 | /** 48 | 6、清空队列数据 49 | */ 50 | - (void)cw_clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 08-二叉搜索树.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 08-二叉搜索树.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/CWBSTCompareModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWBSTCompareModel.h 3 | // 08-二叉搜索树 4 | // 5 | // Created by mac on 2019/5/20. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWBSTCompareModel : NSObject 12 | 13 | @property (nonatomic,assign) int age; 14 | @property (nonatomic,copy) NSString *name; 15 | 16 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/CWBSTCompareModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWBSTCompareModel.m 3 | // 08-二叉搜索树 4 | // 5 | // Created by mac on 2019/5/20. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWBSTCompareModel.h" 10 | 11 | @implementation CWBSTCompareModel 12 | 13 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode 14 | { 15 | // 1、具备可比较行 16 | if ([pareterNode isKindOfClass:[CWBSTCompareModel class]]) { 17 | CWBSTCompareModel *parCompare = pareterNode; 18 | CWBSTCompareModel *newCompare = newNode; 19 | return newCompare.age - parCompare.age; 20 | } 21 | 22 | // 2、NSString 23 | else if ([pareterNode isKindOfClass:[NSString class]]) 24 | { 25 | NSString *pareterValue = pareterNode; 26 | NSString *newValue = newNode; 27 | //NSLog(@"new:%d,prareter:%d,value:%d",newValue.intValue,pareterValue.intValue,newValue.intValue-pareterValue.intValue); 28 | return newValue.intValue - pareterValue.intValue; 29 | }else{ 30 | return (int)newNode - (int)pareterNode; 31 | } 32 | 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/MJBinaryTreeInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTreeInfo.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol MJBinaryTreeInfo 14 | @required 15 | /** 16 | * who is the root node 17 | */ 18 | - (id)root; 19 | /** 20 | * how to get the left child of the node 21 | */ 22 | - (id)left:(id)node; 23 | /** 24 | * how to get the right child of the node 25 | */ 26 | - (id)right:(id)node; 27 | /** 28 | * how to print the node 29 | */ 30 | - (id)string:(id)node; 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/MJBinaryTrees.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTrees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | #import "MJLevelOrderPrinter.h" 12 | #import "MJInorderPrinter.h" 13 | 14 | typedef NS_ENUM(NSInteger, MJPrintStyle) { 15 | MJPrintStyleLevelOrder, 16 | MJPrintStyleInorder 17 | }; 18 | 19 | NS_ASSUME_NONNULL_BEGIN 20 | 21 | @interface MJBinaryTrees : NSObject 22 | + (void)println:(id)tree style:(MJPrintStyle)style; 23 | + (void)println:(id)tree; 24 | 25 | + (void)print:(id)tree style:(MJPrintStyle)style; 26 | + (void)print:(id)tree; 27 | 28 | + (NSString *)printString:(id)tree style:(MJPrintStyle)style; 29 | + (NSString *)printString:(id)tree; 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/MJBinaryTrees.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTrees.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJBinaryTrees.h" 10 | 11 | @implementation MJBinaryTrees 12 | 13 | + (void)println:(id)tree style:(MJPrintStyle)style { 14 | [[self _printerWithTree:tree style:style] println]; 15 | } 16 | 17 | + (void)println:(id)tree { 18 | [self println:tree style:MJPrintStyleLevelOrder]; 19 | } 20 | 21 | + (void)print:(id)tree style:(MJPrintStyle)style { 22 | [[self _printerWithTree:tree style:style] print]; 23 | } 24 | 25 | + (void)print:(id)tree { 26 | [self print:tree style:MJPrintStyleLevelOrder]; 27 | } 28 | 29 | + (NSString *)printString:(id)tree style:(MJPrintStyle)style { 30 | return [self _printerWithTree:tree style:style].printString; 31 | } 32 | 33 | + (NSString *)printString:(id)tree { 34 | return [self printString:tree style:MJPrintStyleLevelOrder]; 35 | } 36 | 37 | + (MJPrinter *)_printerWithTree:(id)tree style:(MJPrintStyle)style { 38 | if (!tree) return nil; 39 | if (style == MJPrintStyleLevelOrder) { 40 | return [MJLevelOrderPrinter printerWithTree:tree]; 41 | } 42 | return [MJInorderPrinter printerWithTree:tree]; 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/MJPrinter/MJInorderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJInorderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌──100 15 | ┌──85 16 | │ └──71 17 | ┌──69 18 | 38 19 | │ ┌──36 20 | │ ┌──34 21 | │ │ └──29 22 | └──18 23 | └──4 24 | */ 25 | @interface MJInorderPrinter : MJPrinter 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/MJPrinter/MJLevelOrderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJLevelOrderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌───38──┐ 15 | │ │ 16 | ┌─18─┐ 69─┐ 17 | │ │ │ 18 | 4 ┌─34─┐ ┌─85─┐ 19 | │ │ │ │ 20 | 29 36 71 100 21 | */ 22 | @interface MJLevelOrderPrinter : MJPrinter 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/MJPrinter/MJPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MJPrinter : NSObject 15 | @property (nonatomic, strong) id tree; 16 | + (instancetype)printerWithTree:(id)tree; 17 | - (void)println; 18 | - (void)print; 19 | - (NSString *)printString; 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/MJPrinter/MJPrinter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | @interface MJPrinter() 12 | @end 13 | 14 | @implementation MJPrinter 15 | 16 | + (instancetype)printerWithTree:(id)tree { 17 | MJPrinter *printer = [[self alloc] init]; 18 | printer.tree = tree; 19 | return printer; 20 | } 21 | 22 | - (void)println { 23 | [self print]; 24 | printf("\n"); 25 | } 26 | 27 | - (void)print { 28 | printf("%s", self.printString.UTF8String); 29 | } 30 | 31 | - (NSString *)printString { 32 | return nil; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/NSString+Trees.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface NSString (Trees) 14 | + (NSString *)mj_blank:(NSUInteger)count; 15 | - (NSString *)mj_repeat:(NSUInteger)count; 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Structures/08-二叉搜索树/08-二叉搜索树/MJBinaryTrees/NSString+Trees.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "NSString+Trees.h" 10 | 11 | @implementation NSString (Trees) 12 | 13 | - (NSString *)mj_repeat:(NSUInteger)count { 14 | NSMutableString *string = [NSMutableString string]; 15 | while (count-- > 0) { 16 | [string appendString:self]; 17 | } 18 | return string; 19 | } 20 | 21 | + (NSString *)mj_blank:(NSUInteger)count { 22 | return [@" " mj_repeat:count]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/09-AVL平衡树/09-AVL平衡树.xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树.xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 09-AVL平衡树.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/CWAVLCompareModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWAVLCompareModel.h 3 | // 09-AVL平衡树 4 | // 5 | // Created by mac on 2019/5/30. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWAVLCompareModel : NSObject 12 | 13 | @property (nonatomic,assign) int age; 14 | @property (nonatomic,copy) NSString *name; 15 | 16 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/CWAVLCompareModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWAVLCompareModel.m 3 | // 09-AVL平衡树 4 | // 5 | // Created by mac on 2019/5/30. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWAVLCompareModel.h" 10 | 11 | @implementation CWAVLCompareModel 12 | 13 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode 14 | { 15 | // 1、具备可比较行 16 | if ([pareterNode isKindOfClass:[CWAVLCompareModel class]]) { 17 | CWAVLCompareModel *parCompare = pareterNode; 18 | CWAVLCompareModel *newCompare = newNode; 19 | return newCompare.age - parCompare.age; 20 | } 21 | 22 | // 2、NSString 23 | else if ([pareterNode isKindOfClass:[NSString class]]) 24 | { 25 | NSString *pareterValue = pareterNode; 26 | NSString *newValue = newNode; 27 | //NSLog(@"new:%d,prareter:%d,value:%d",newValue.intValue,pareterValue.intValue,newValue.intValue-pareterValue.intValue); 28 | return newValue.intValue - pareterValue.intValue; 29 | }else{ 30 | return (int)newNode - (int)pareterNode; 31 | } 32 | 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/MJBinaryTreeInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTreeInfo.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol MJBinaryTreeInfo 14 | @required 15 | /** 16 | * who is the root node 17 | */ 18 | - (id)root; 19 | /** 20 | * how to get the left child of the node 21 | */ 22 | - (id)left:(id)node; 23 | /** 24 | * how to get the right child of the node 25 | */ 26 | - (id)right:(id)node; 27 | /** 28 | * how to print the node 29 | */ 30 | - (id)string:(id)node; 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/MJBinaryTrees.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTrees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | #import "MJLevelOrderPrinter.h" 12 | #import "MJInorderPrinter.h" 13 | 14 | typedef NS_ENUM(NSInteger, MJPrintStyle) { 15 | MJPrintStyleLevelOrder, 16 | MJPrintStyleInorder 17 | }; 18 | 19 | NS_ASSUME_NONNULL_BEGIN 20 | 21 | @interface MJBinaryTrees : NSObject 22 | + (void)println:(id)tree style:(MJPrintStyle)style; 23 | + (void)println:(id)tree; 24 | 25 | + (void)print:(id)tree style:(MJPrintStyle)style; 26 | + (void)print:(id)tree; 27 | 28 | + (NSString *)printString:(id)tree style:(MJPrintStyle)style; 29 | + (NSString *)printString:(id)tree; 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/MJPrinter/MJInorderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJInorderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌──100 15 | ┌──85 16 | │ └──71 17 | ┌──69 18 | 38 19 | │ ┌──36 20 | │ ┌──34 21 | │ │ └──29 22 | └──18 23 | └──4 24 | */ 25 | @interface MJInorderPrinter : MJPrinter 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/MJPrinter/MJLevelOrderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJLevelOrderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌───38──┐ 15 | │ │ 16 | ┌─18─┐ 69─┐ 17 | │ │ │ 18 | 4 ┌─34─┐ ┌─85─┐ 19 | │ │ │ │ 20 | 29 36 71 100 21 | */ 22 | @interface MJLevelOrderPrinter : MJPrinter 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/MJPrinter/MJPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MJPrinter : NSObject 15 | @property (nonatomic, strong) id tree; 16 | + (instancetype)printerWithTree:(id)tree; 17 | - (void)println; 18 | - (void)print; 19 | - (NSString *)printString; 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/MJPrinter/MJPrinter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | @interface MJPrinter() 12 | @end 13 | 14 | @implementation MJPrinter 15 | 16 | + (instancetype)printerWithTree:(id)tree { 17 | MJPrinter *printer = [[self alloc] init]; 18 | printer.tree = tree; 19 | return printer; 20 | } 21 | 22 | - (void)println { 23 | [self print]; 24 | printf("\n"); 25 | } 26 | 27 | - (void)print { 28 | printf("%s", self.printString.UTF8String); 29 | } 30 | 31 | - (NSString *)printString { 32 | return nil; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/NSString+Trees.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface NSString (Trees) 14 | + (NSString *)mj_blank:(NSUInteger)count; 15 | - (NSString *)mj_repeat:(NSUInteger)count; 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Structures/09-AVL平衡树/09-AVL平衡树/MJBinaryTrees/NSString+Trees.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "NSString+Trees.h" 10 | 11 | @implementation NSString (Trees) 12 | 13 | - (NSString *)mj_repeat:(NSUInteger)count { 14 | NSMutableString *string = [NSMutableString string]; 15 | while (count-- > 0) { 16 | [string appendString:self]; 17 | } 18 | return string; 19 | } 20 | 21 | + (NSString *)mj_blank:(NSUInteger)count { 22 | return [@" " mj_repeat:count]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 10-RBT红黑树(RedBlackTree).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 10-RBT红黑树(RedBlackTree).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/CWRBTCompareModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBTCompareModel.h 3 | // 10-RBT红黑树(RedBlackTree) 4 | // 5 | // Created by mac on 2019/6/3. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWRBTCompareModel : NSObject 12 | 13 | @property (nonatomic,assign) int age; 14 | @property (nonatomic,copy) NSString *name; 15 | 16 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/CWRBTCompareModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBTCompareModel.m 3 | // 10-RBT红黑树(RedBlackTree) 4 | // 5 | // Created by mac on 2019/6/3. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWRBTCompareModel.h" 10 | 11 | @implementation CWRBTCompareModel 12 | 13 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode 14 | { 15 | // 1、具备可比较行 16 | if ([pareterNode isKindOfClass:[CWRBTCompareModel class]]) { 17 | CWRBTCompareModel *parCompare = pareterNode; 18 | CWRBTCompareModel *newCompare = newNode; 19 | return newCompare.age - parCompare.age; 20 | } 21 | 22 | // 2、NSString 23 | else if ([pareterNode isKindOfClass:[NSString class]]) 24 | { 25 | NSString *pareterValue = pareterNode; 26 | NSString *newValue = newNode; 27 | //NSLog(@"new:%d,prareter:%d,value:%d",newValue.intValue,pareterValue.intValue,newValue.intValue-pareterValue.intValue); 28 | 29 | NSLog(@"compare:%d",[newValue compare:pareterValue]); 30 | return [newValue compare:pareterValue]; 31 | // return newValue.intValue - pareterValue.intValue; 32 | }else{ 33 | return (int)newNode - (int)pareterNode; 34 | } 35 | 36 | } 37 | 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/MJBinaryTreeInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTreeInfo.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol MJBinaryTreeInfo 14 | @required 15 | /** 16 | * who is the root node 17 | */ 18 | - (id)root; 19 | /** 20 | * how to get the left child of the node 21 | */ 22 | - (id)left:(id)node; 23 | /** 24 | * how to get the right child of the node 25 | */ 26 | - (id)right:(id)node; 27 | /** 28 | * how to print the node 29 | */ 30 | - (id)string:(id)node; 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/MJBinaryTrees.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTrees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | #import "MJLevelOrderPrinter.h" 12 | #import "MJInorderPrinter.h" 13 | 14 | typedef NS_ENUM(NSInteger, MJPrintStyle) { 15 | MJPrintStyleLevelOrder, 16 | MJPrintStyleInorder 17 | }; 18 | 19 | NS_ASSUME_NONNULL_BEGIN 20 | 21 | @interface MJBinaryTrees : NSObject 22 | + (void)println:(id)tree style:(MJPrintStyle)style; 23 | + (void)println:(id)tree; 24 | 25 | + (void)print:(id)tree style:(MJPrintStyle)style; 26 | + (void)print:(id)tree; 27 | 28 | + (NSString *)printString:(id)tree style:(MJPrintStyle)style; 29 | + (NSString *)printString:(id)tree; 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/MJPrinter/MJInorderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJInorderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌──100 15 | ┌──85 16 | │ └──71 17 | ┌──69 18 | 38 19 | │ ┌──36 20 | │ ┌──34 21 | │ │ └──29 22 | └──18 23 | └──4 24 | */ 25 | @interface MJInorderPrinter : MJPrinter 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/MJPrinter/MJLevelOrderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJLevelOrderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌───38──┐ 15 | │ │ 16 | ┌─18─┐ 69─┐ 17 | │ │ │ 18 | 4 ┌─34─┐ ┌─85─┐ 19 | │ │ │ │ 20 | 29 36 71 100 21 | */ 22 | @interface MJLevelOrderPrinter : MJPrinter 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/MJPrinter/MJPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MJPrinter : NSObject 15 | @property (nonatomic, strong) id tree; 16 | + (instancetype)printerWithTree:(id)tree; 17 | - (void)println; 18 | - (void)print; 19 | - (NSString *)printString; 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/MJPrinter/MJPrinter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | @interface MJPrinter() 12 | @end 13 | 14 | @implementation MJPrinter 15 | 16 | + (instancetype)printerWithTree:(id)tree { 17 | MJPrinter *printer = [[self alloc] init]; 18 | printer.tree = tree; 19 | return printer; 20 | } 21 | 22 | - (void)println { 23 | [self print]; 24 | printf("\n"); 25 | } 26 | 27 | - (void)print { 28 | printf("%s", self.printString.UTF8String); 29 | } 30 | 31 | - (NSString *)printString { 32 | return nil; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/NSString+Trees.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface NSString (Trees) 14 | + (NSString *)mj_blank:(NSUInteger)count; 15 | - (NSString *)mj_repeat:(NSUInteger)count; 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/MJBinaryTrees/NSString+Trees.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "NSString+Trees.h" 10 | 11 | @implementation NSString (Trees) 12 | 13 | - (NSString *)mj_repeat:(NSUInteger)count { 14 | NSMutableString *string = [NSMutableString string]; 15 | while (count-- > 0) { 16 | [string appendString:self]; 17 | } 18 | return string; 19 | } 20 | 21 | + (NSString *)mj_blank:(NSUInteger)count { 22 | return [@" " mj_repeat:count]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Structures/10-RBT红黑树(RedBlackTree) /10-RBT红黑树(RedBlackTree)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 10-RBT红黑树(RedBlackTree) 4 | // 5 | // Created by mac on 2019/6/3. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTrees.h" 11 | #import "CWRBTree.h" 12 | int main(int argc, const char * argv[]) { 13 | @autoreleasepool { 14 | 15 | 16 | 17 | // NSMutableArray *array = [NSMutableArray arrayWithObjects:@"age", @"ward", @"car",nil]; 18 | // CWRBTree *rb = [[CWRBTree alloc] init]; 19 | // for (int i = 0; i < array.count; i ++) { 20 | // [rb cw_addE:array[i]]; 21 | // [MJBinaryTrees println:rb]; 22 | // NSLog(@"------------------"); 23 | // } 24 | 25 | 26 | CWRBTree *rb2 = [[CWRBTree alloc] init]; 27 | for (int i = 0; i < 10; i ++) { 28 | [rb2 cw_addE:[NSString stringWithFormat:@"a%d",i+1]]; 29 | [MJBinaryTrees println:rb2]; 30 | NSLog(@"------------------"); 31 | } 32 | // [MJBinaryTrees println:rb2]; 33 | // NSLog(@"------------------"); 34 | // 35 | // [rb2 cw_removeE:@"29"]; 36 | // [MJBinaryTrees println:rb2]; 37 | // NSLog(@"------------------"); 38 | 39 | 40 | 41 | 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/11-集合(Set)/11-集合(Set).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 11-集合(Set).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set)/CWRBSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBSet.h 3 | // 11-集合(Set) 4 | // 5 | // Created by mac on 2019/6/6. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWRBSet : NSObject 12 | @property (nonatomic,assign) int size; 13 | 14 | /** 15 | 1、新增某元素 16 | */ 17 | - (void)cw_addE:(id)E; 18 | 19 | /** 20 | 2、移除E、BST元素 21 | */ 22 | - (id)cw_removeE:(id)E; 23 | 24 | - (id)cw_removeBST:(CWRBSet *)bst; 25 | 26 | /** 27 | 3、清空数据数据 28 | */ 29 | - (void)cw_clear; 30 | 31 | /** 32 | 4、集合的大小 33 | */ 34 | - (int)cw_size; 35 | 36 | /** 37 | 5、集合是否为空 38 | */ 39 | - (BOOL)cw_isEmpty; 40 | 41 | /** 42 | 6、遍历集合的数据 43 | */ 44 | - (void)cw_traversal:(CWRBSet *)node; 45 | 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set)/CWRBTCompareModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBTCompareModel.h 3 | // 10-RBT红黑树(RedBlackTree) 4 | // 5 | // Created by mac on 2019/6/3. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWRBTCompareModel : NSObject 12 | 13 | @property (nonatomic,assign) int age; 14 | @property (nonatomic,copy) NSString *name; 15 | 16 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set)/CWRBTCompareModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBTCompareModel.m 3 | // 10-RBT红黑树(RedBlackTree) 4 | // 5 | // Created by mac on 2019/6/3. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWRBTCompareModel.h" 10 | 11 | @implementation CWRBTCompareModel 12 | 13 | - (int)compareValue:(id)pareterNode oldValue:(id)newNode 14 | { 15 | // 1、具备可比较行 16 | if ([pareterNode isKindOfClass:[CWRBTCompareModel class]]) { 17 | CWRBTCompareModel *parCompare = pareterNode; 18 | CWRBTCompareModel *newCompare = newNode; 19 | return newCompare.age - parCompare.age; 20 | } 21 | 22 | // 2、NSString 23 | else if ([pareterNode isKindOfClass:[NSString class]]) 24 | { 25 | NSString *pareterValue = pareterNode; 26 | NSString *newValue = newNode; 27 | //NSLog(@"new:%d,prareter:%d,value:%d",newValue.intValue,pareterValue.intValue,newValue.intValue-pareterValue.intValue); 28 | return newValue.intValue - pareterValue.intValue; 29 | }else{ 30 | return (int)newNode - (int)pareterNode; 31 | } 32 | 33 | } 34 | 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /Structures/11-集合(Set)/11-集合(Set)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 11-集合(Set) 4 | // 5 | // Created by mac on 2019/6/6. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWRBSet.h" 11 | int main(int argc, const char * argv[]) { 12 | @autoreleasepool { 13 | 14 | 15 | // 集合:去除重复数据 16 | 17 | CWRBSet *set = [[CWRBSet alloc] init]; 18 | for (int i = 0; i < 10; i ++) { 19 | [set cw_addE:[NSString stringWithFormat:@"%d",i+1]]; 20 | } 21 | 22 | for (int i = 0; i < 10; i ++) { 23 | [set cw_addE:[NSString stringWithFormat:@"%d",i+1]]; 24 | } 25 | 26 | [set cw_traversal:set]; 27 | } 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/12-映射(Map)/12-映射(Map).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/12-映射(Map)/12-映射(Map).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 12-映射(Map).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 12-映射(Map).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/CWRBTreeCompare.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBTreeCompare.h 3 | // 12-映射(Map) 4 | // 5 | // Created by 程金伟 on 2019/6/7. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWRBTreeCompare : NSObject 12 | 13 | @property (nonatomic,assign) int age; 14 | @property (nonatomic,copy) NSString *name; 15 | 16 | - (int)compareValue:(id)oldN oldValue:(id)newN; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/CWRBTreeCompare.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBTreeCompare.m 3 | // 12-映射(Map) 4 | // 5 | // Created by 程金伟 on 2019/6/7. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWRBTreeCompare.h" 10 | 11 | @implementation CWRBTreeCompare 12 | 13 | - (int)compareValue:(id)oldN oldValue:(id)newN 14 | { 15 | // 1、具备可比较行 16 | if ([oldN isKindOfClass:[CWRBTreeCompare class]]) { 17 | CWRBTreeCompare *oldC = oldN; 18 | CWRBTreeCompare *newC = newN; 19 | return oldC.age - newC.age; 20 | } 21 | 22 | // 2、NSString 23 | else if ([oldN isKindOfClass:[NSString class]]) 24 | { 25 | NSString *oldValue = oldN; 26 | NSString *newValue = newN; 27 | return [newValue compare:oldValue]; 28 | //return newValue.intValue - oldValue.intValue; 29 | }else{ 30 | return (int)newN - (int)oldN; 31 | } 32 | 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/CWRBTreeMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWRBTreeMap.h 3 | // 12-映射(Map) 4 | // 5 | // Created by 程金伟 on 2019/6/7. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWRBTreeMap : NSObject 12 | @property (nonatomic,assign) int size; 13 | 14 | /** 15 | 1、新增某元素 16 | */ 17 | - (void)cw_addNodeWithKey:(id)key value:(id)value; 18 | 19 | /** 20 | 2、移除E、BST元素 21 | */ 22 | - (id)cw_removeE:(id)key; 23 | 24 | - (id)cw_removeBST:(CWRBTreeMap *)bst; 25 | 26 | /** 27 | 3、查找key对应的节点 28 | */ 29 | - (CWRBTreeMap *)getNodeWithKey:(id)key; 30 | 31 | /** 32 | 4、是否包含value的node 33 | */ 34 | - (BOOL)isContainValue:(id)value; 35 | 36 | /** 37 | 5、清空数据数据 38 | */ 39 | - (void)cw_clear; 40 | 41 | /** 42 | 6、集合的大小 43 | */ 44 | - (int)cw_size; 45 | 46 | /** 47 | 7、集合是否为空 48 | */ 49 | - (BOOL)cw_isEmpty; 50 | 51 | /** 52 | 8、遍历集合的数据 53 | */ 54 | - (void)cw_traversal:(CWRBTreeMap *)node; 55 | 56 | @end 57 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/MJBinaryTreeInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTreeInfo.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol MJBinaryTreeInfo 14 | @required 15 | /** 16 | * who is the root node 17 | */ 18 | - (id)root; 19 | /** 20 | * how to get the left child of the node 21 | */ 22 | - (id)left:(id)node; 23 | /** 24 | * how to get the right child of the node 25 | */ 26 | - (id)right:(id)node; 27 | /** 28 | * how to print the node 29 | */ 30 | - (id)string:(id)node; 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/MJBinaryTrees.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTrees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | #import "MJLevelOrderPrinter.h" 12 | #import "MJInorderPrinter.h" 13 | 14 | typedef NS_ENUM(NSInteger, MJPrintStyle) { 15 | MJPrintStyleLevelOrder, 16 | MJPrintStyleInorder 17 | }; 18 | 19 | NS_ASSUME_NONNULL_BEGIN 20 | 21 | @interface MJBinaryTrees : NSObject 22 | + (void)println:(id)tree style:(MJPrintStyle)style; 23 | + (void)println:(id)tree; 24 | 25 | + (void)print:(id)tree style:(MJPrintStyle)style; 26 | + (void)print:(id)tree; 27 | 28 | + (NSString *)printString:(id)tree style:(MJPrintStyle)style; 29 | + (NSString *)printString:(id)tree; 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/MJPrinter/MJInorderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJInorderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌──100 15 | ┌──85 16 | │ └──71 17 | ┌──69 18 | 38 19 | │ ┌──36 20 | │ ┌──34 21 | │ │ └──29 22 | └──18 23 | └──4 24 | */ 25 | @interface MJInorderPrinter : MJPrinter 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/MJPrinter/MJLevelOrderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJLevelOrderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌───38──┐ 15 | │ │ 16 | ┌─18─┐ 69─┐ 17 | │ │ │ 18 | 4 ┌─34─┐ ┌─85─┐ 19 | │ │ │ │ 20 | 29 36 71 100 21 | */ 22 | @interface MJLevelOrderPrinter : MJPrinter 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/MJPrinter/MJPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MJPrinter : NSObject 15 | @property (nonatomic, strong) id tree; 16 | + (instancetype)printerWithTree:(id)tree; 17 | - (void)println; 18 | - (void)print; 19 | - (NSString *)printString; 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/MJPrinter/MJPrinter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | @interface MJPrinter() 12 | @end 13 | 14 | @implementation MJPrinter 15 | 16 | + (instancetype)printerWithTree:(id)tree { 17 | MJPrinter *printer = [[self alloc] init]; 18 | printer.tree = tree; 19 | return printer; 20 | } 21 | 22 | - (void)println { 23 | [self print]; 24 | printf("\n"); 25 | } 26 | 27 | - (void)print { 28 | printf("%s", self.printString.UTF8String); 29 | } 30 | 31 | - (NSString *)printString { 32 | return nil; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/NSString+Trees.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface NSString (Trees) 14 | + (NSString *)mj_blank:(NSUInteger)count; 15 | - (NSString *)mj_repeat:(NSUInteger)count; 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/MJBinaryTrees/NSString+Trees.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "NSString+Trees.h" 10 | 11 | @implementation NSString (Trees) 12 | 13 | - (NSString *)mj_repeat:(NSUInteger)count { 14 | NSMutableString *string = [NSMutableString string]; 15 | while (count-- > 0) { 16 | [string appendString:self]; 17 | } 18 | return string; 19 | } 20 | 21 | + (NSString *)mj_blank:(NSUInteger)count { 22 | return [@" " mj_repeat:count]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Structures/12-映射(Map)/12-映射(Map)/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 12-映射(Map) 4 | // 5 | // Created by 程金伟 on 2019/6/7. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CWRBTreeMap.h" 11 | #import "MJBinaryTrees.h" 12 | int main(int argc, const char * argv[]) { 13 | @autoreleasepool { 14 | 15 | CWRBTreeMap *map = [[CWRBTreeMap alloc] init]; 16 | // NSMutableArray *array = [NSMutableArray arrayWithObjects:@"a",@"b",@"c",nil]; 17 | // for (int i = 0; i < array.count; i ++) { 18 | // [map cw_addE:array[i]]; 19 | // } 20 | 21 | [map cw_addNodeWithKey:@"a" value:@"18"]; 22 | [map cw_addNodeWithKey:@"b" value:@"28"]; 23 | [map cw_addNodeWithKey:@"c" value:@"32"]; 24 | [map cw_addNodeWithKey:@"c" value:@"80"]; 25 | 26 | [MJBinaryTrees println:map]; 27 | 28 | //[map cw_traversal:map]; 29 | 30 | //CWRBTreeMap *one = [[CWRBTreeMap alloc] init]; 31 | NSLog(@"contain:%d",[map isContainValue:@"80"]); 32 | 33 | CWRBTreeMap *two = [map getNodeWithKey:@"a"]; 34 | 35 | 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 13-哈希值(hash).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 13-哈希值(hash).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/CWHashMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWHashMap.h 3 | // 13-哈希值(hash) 4 | // 5 | // Created by mac on 2019/6/11. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class CWHashMapModel; 12 | 13 | @interface CWHashMap : NSObject 14 | 15 | /**< 哈希表大小 */ 16 | @property (nonatomic,assign) int size; 17 | /**< 哈希表 */ 18 | @property (nonatomic,strong) NSMutableArray *hashTable; 19 | 20 | /** 21 | 1、哈希表新增某元素 22 | */ 23 | - (void)cw_addNodeWithKey:(id)key value:(id)value; 24 | 25 | /** 26 | 2、哈希表移除E、BST元素 27 | */ 28 | - (id)cw_removeForKey:(id)key; 29 | 30 | /** 31 | 3、哈希表查找key对应的节点 32 | */ 33 | - (CWHashMapModel *)getNodeWithKey:(id)key; 34 | 35 | /** 36 | 4、哈希表是否包含value的node 37 | */ 38 | - (BOOL)isContainValue:(id)value key:(id)key; 39 | 40 | /** 41 | 5、哈希表清空数据数据 42 | */ 43 | - (void)cw_clear; 44 | 45 | /** 46 | 6、哈希表的大小 47 | */ 48 | - (int)cw_size; 49 | 50 | /** 51 | 7、哈希表是否为空 52 | */ 53 | - (BOOL)cw_isEmpty; 54 | 55 | /** 56 | 8、哈希表遍历 57 | */ 58 | - (void)traversal; 59 | 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/CWHashMapCompare.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWHashMapCompare.h 3 | // 13-哈希值(hash) 4 | // 5 | // Created by mac on 2019/6/12. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWHashMapCompare : NSObject 12 | 13 | /**< 1、比较key值大小方法 */ 14 | - (int)compareValue:(id)oldN oldValue:(id)newN; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/CWHashMapCompare.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWHashMapCompare.m 3 | // 13-哈希值(hash) 4 | // 5 | // Created by mac on 2019/6/12. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWHashMapCompare.h" 10 | #import "CWHashMapModel.h" 11 | 12 | @implementation CWHashMapCompare 13 | 14 | /**< 1、比较方法 */ 15 | - (int)compareValue:(id)oldN oldValue:(id)newN 16 | { 17 | // 1、具备可比较行 18 | if ([oldN isKindOfClass:[CWHashMapModel class]]) { 19 | CWHashMapModel *oldC = oldN; 20 | CWHashMapModel *newC = newN; 21 | return (int)(oldC.hashV - newC.hashV); 22 | } 23 | // 2、NSString 24 | else if ([oldN isKindOfClass:[NSString class]]) 25 | { 26 | NSString *oldValue = oldN; 27 | NSString *newValue = newN; 28 | return [newValue compare:oldValue]; 29 | }else{ 30 | return (int)newN - (int)oldN; 31 | } 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/MJBinaryTreeInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTreeInfo.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol MJBinaryTreeInfo 14 | @required 15 | /** 16 | * who is the root node 17 | */ 18 | - (id)root; 19 | /** 20 | * how to get the left child of the node 21 | */ 22 | - (id)left:(id)node; 23 | /** 24 | * how to get the right child of the node 25 | */ 26 | - (id)right:(id)node; 27 | /** 28 | * how to print the node 29 | */ 30 | - (id)string:(id)node; 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/MJBinaryTrees.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTrees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | #import "MJLevelOrderPrinter.h" 12 | #import "MJInorderPrinter.h" 13 | 14 | typedef NS_ENUM(NSInteger, MJPrintStyle) { 15 | MJPrintStyleLevelOrder, 16 | MJPrintStyleInorder 17 | }; 18 | 19 | NS_ASSUME_NONNULL_BEGIN 20 | 21 | @interface MJBinaryTrees : NSObject 22 | + (void)println:(id)tree style:(MJPrintStyle)style; 23 | + (void)println:(id)tree; 24 | 25 | + (void)print:(id)tree style:(MJPrintStyle)style; 26 | + (void)print:(id)tree; 27 | 28 | + (NSString *)printString:(id)tree style:(MJPrintStyle)style; 29 | + (NSString *)printString:(id)tree; 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/MJPrinter/MJInorderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJInorderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌──100 15 | ┌──85 16 | │ └──71 17 | ┌──69 18 | 38 19 | │ ┌──36 20 | │ ┌──34 21 | │ │ └──29 22 | └──18 23 | └──4 24 | */ 25 | @interface MJInorderPrinter : MJPrinter 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/MJPrinter/MJLevelOrderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJLevelOrderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌───38──┐ 15 | │ │ 16 | ┌─18─┐ 69─┐ 17 | │ │ │ 18 | 4 ┌─34─┐ ┌─85─┐ 19 | │ │ │ │ 20 | 29 36 71 100 21 | */ 22 | @interface MJLevelOrderPrinter : MJPrinter 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/MJPrinter/MJPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MJPrinter : NSObject 15 | @property (nonatomic, strong) id tree; 16 | + (instancetype)printerWithTree:(id)tree; 17 | - (void)println; 18 | - (void)print; 19 | - (NSString *)printString; 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/MJPrinter/MJPrinter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | @interface MJPrinter() 12 | @end 13 | 14 | @implementation MJPrinter 15 | 16 | + (instancetype)printerWithTree:(id)tree { 17 | MJPrinter *printer = [[self alloc] init]; 18 | printer.tree = tree; 19 | return printer; 20 | } 21 | 22 | - (void)println { 23 | [self print]; 24 | printf("\n"); 25 | } 26 | 27 | - (void)print { 28 | printf("%s", self.printString.UTF8String); 29 | } 30 | 31 | - (NSString *)printString { 32 | return nil; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/NSString+Trees.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface NSString (Trees) 14 | + (NSString *)mj_blank:(NSUInteger)count; 15 | - (NSString *)mj_repeat:(NSUInteger)count; 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Structures/13-哈希值(hash)/13-哈希值(hash)/MJBinaryTrees/NSString+Trees.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "NSString+Trees.h" 10 | 11 | @implementation NSString (Trees) 12 | 13 | - (NSString *)mj_repeat:(NSUInteger)count { 14 | NSMutableString *string = [NSMutableString string]; 15 | while (count-- > 0) { 16 | [string appendString:self]; 17 | } 18 | return string; 19 | } 20 | 21 | + (NSString *)mj_blank:(NSUInteger)count { 22 | return [@" " mj_repeat:count]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 14-二叉堆(BinaryHeap).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/CWMaxBinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWMaxBinaryHeap.h 3 | // 14-二叉堆(BinaryHeap) 4 | // 5 | // Created by mac on 2019/6/21. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWMaxBinaryHeap : NSObject 12 | 13 | @property (nonatomic,assign) int size; 14 | @property (nonatomic,strong) NSMutableArray *binaryHeaps; 15 | @property (nonatomic,assign) BOOL MaxHeap; 16 | 17 | /** 18 | 0、批量建堆 19 | */ 20 | - (void)batchHeaps:(NSArray *)array; 21 | /** 22 | 1、二叉堆的size 23 | */ 24 | - (int)heap_size; 25 | 26 | /** 27 | 2、二叉堆是否为空 28 | */ 29 | - (BOOL)isEmpty; 30 | 31 | /** 32 | 3、二叉堆的清空 33 | */ 34 | - (void)clear; 35 | 36 | /** 37 | 4、二叉堆添加元素 38 | */ 39 | - (void)addEle:(id)ele; 40 | 41 | /** 42 | 5、获取堆顶元素 43 | */ 44 | - (id)getTop; 45 | 46 | /** 47 | 6、删除堆顶元素 48 | */ 49 | - (id)removeTop; 50 | 51 | /** 52 | 7、删除堆顶元素同时插入一个新元素 53 | */ 54 | - (id)replaceTopWithEle:(id)ele; 55 | 56 | 57 | @end 58 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/MJBinaryTreeInfo.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTreeInfo.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol MJBinaryTreeInfo 14 | @required 15 | /** 16 | * who is the root node 17 | */ 18 | - (id)root; 19 | /** 20 | * how to get the left child of the node 21 | */ 22 | - (id)left:(id)node; 23 | /** 24 | * how to get the right child of the node 25 | */ 26 | - (id)right:(id)node; 27 | /** 28 | * how to print the node 29 | */ 30 | - (id)string:(id)node; 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/MJBinaryTrees.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJBinaryTrees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | #import "MJLevelOrderPrinter.h" 12 | #import "MJInorderPrinter.h" 13 | 14 | typedef NS_ENUM(NSInteger, MJPrintStyle) { 15 | MJPrintStyleLevelOrder, 16 | MJPrintStyleInorder 17 | }; 18 | 19 | NS_ASSUME_NONNULL_BEGIN 20 | 21 | @interface MJBinaryTrees : NSObject 22 | + (void)println:(id)tree style:(MJPrintStyle)style; 23 | + (void)println:(id)tree; 24 | 25 | + (void)print:(id)tree style:(MJPrintStyle)style; 26 | + (void)print:(id)tree; 27 | 28 | + (NSString *)printString:(id)tree style:(MJPrintStyle)style; 29 | + (NSString *)printString:(id)tree; 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/MJPrinter/MJInorderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJInorderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌──100 15 | ┌──85 16 | │ └──71 17 | ┌──69 18 | 38 19 | │ ┌──36 20 | │ ┌──34 21 | │ │ └──29 22 | └──18 23 | └──4 24 | */ 25 | @interface MJInorderPrinter : MJPrinter 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/MJPrinter/MJLevelOrderPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJLevelOrderPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /* 14 | ┌───38──┐ 15 | │ │ 16 | ┌─18─┐ 69─┐ 17 | │ │ │ 18 | 4 ┌─34─┐ ┌─85─┐ 19 | │ │ │ │ 20 | 29 36 71 100 21 | */ 22 | @interface MJLevelOrderPrinter : MJPrinter 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/MJPrinter/MJPrinter.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJBinaryTreeInfo.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface MJPrinter : NSObject 15 | @property (nonatomic, strong) id tree; 16 | + (instancetype)printerWithTree:(id)tree; 17 | - (void)println; 18 | - (void)print; 19 | - (NSString *)printString; 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/MJPrinter/MJPrinter.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJPrinter.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "MJPrinter.h" 10 | 11 | @interface MJPrinter() 12 | @end 13 | 14 | @implementation MJPrinter 15 | 16 | + (instancetype)printerWithTree:(id)tree { 17 | MJPrinter *printer = [[self alloc] init]; 18 | printer.tree = tree; 19 | return printer; 20 | } 21 | 22 | - (void)println { 23 | [self print]; 24 | printf("\n"); 25 | } 26 | 27 | - (void)print { 28 | printf("%s", self.printString.UTF8String); 29 | } 30 | 31 | - (NSString *)printString { 32 | return nil; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/NSString+Trees.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.h 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface NSString (Trees) 14 | + (NSString *)mj_blank:(NSUInteger)count; 15 | - (NSString *)mj_repeat:(NSUInteger)count; 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /Structures/14-二叉堆(BinaryHeap)/14-二叉堆(BinaryHeap)/MJBinaryTrees/NSString+Trees.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+Trees.m 3 | // BinaryTreePrinterOC 4 | // 5 | // Created by MJ Lee on 2019/5/1. 6 | // Copyright © 2019 MJ Lee. All rights reserved. 7 | // 8 | 9 | #import "NSString+Trees.h" 10 | 11 | @implementation NSString (Trees) 12 | 13 | - (NSString *)mj_repeat:(NSUInteger)count { 14 | NSMutableString *string = [NSMutableString string]; 15 | while (count-- > 0) { 16 | [string appendString:self]; 17 | } 18 | return string; 19 | } 20 | 21 | + (NSString *)mj_blank:(NSUInteger)count { 22 | return [@" " mj_repeat:count]; 23 | } 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 15-优先级队列(Priority Queue).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 15-优先级队列(Priority Queue).xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 15-优先级队列(Priority Queue).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue)/CWPriorityQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWPriorityQueue.h 3 | // 15-优先级队列(Priority Queue) 4 | // 5 | // Created by mac on 2019/7/5. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | @class CWPriorityQueueModel; 11 | 12 | typedef enum : NSUInteger { 13 | CWPriorityMaxAgeQueue = 0, // 年龄最大 14 | CWPriorityMinAgeQueue = 1, // 年龄最小 15 | CWPriorityDateQueue = 2, // 添加时间 16 | } CWPriorityQueueType; 17 | @interface CWPriorityQueue : NSObject 18 | 19 | @property (nonatomic,assign) NSInteger size; 20 | @property (nonatomic,strong) NSMutableArray *arrays; 21 | //@property (nonatomic,assign) BOOL MaxHeap; 22 | @property(nonatomic,assign) CWPriorityQueueType compareType; 23 | 24 | /** 25 | 1、优先级队列添加元素 26 | */ 27 | - (void)enQueue:(id)ele; 28 | 29 | /** 30 | 2、优先级队列删除元素 31 | */ 32 | - (id)deQueue; 33 | 34 | /** 35 | 3、获取队列头元素 36 | */ 37 | - (id)queue_front; 38 | 39 | /** 40 | 4、优先级队列的size 41 | */ 42 | - (int)queue_size; 43 | 44 | /** 45 | 5、优先级队列是否为空 46 | */ 47 | - (BOOL)queue_isEmpty; 48 | 49 | /** 50 | 6、优先级队列的的清空 51 | */ 52 | - (void)queue_clear; 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue)/CWPriorityQueueModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWPriorityQueueModel.h 3 | // 15-优先级队列(Priority Queue) 4 | // 5 | // Created by mac on 2019/7/5. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWPriorityQueueModel : NSObject 12 | 13 | - (instancetype)initWithName:(NSString *)name age:(NSInteger)age dateStr:(NSString *)dateStr; 14 | @property (nonatomic,copy) NSString *name; 15 | @property (nonatomic,assign) NSInteger age; 16 | @property (nonatomic,copy)NSString *dateStr; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Structures/15-优先级队列(Priority Queue)/15-优先级队列(Priority Queue)/CWPriorityQueueModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWPriorityQueueModel.m 3 | // 15-优先级队列(Priority Queue) 4 | // 5 | // Created by mac on 2019/7/5. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import "CWPriorityQueueModel.h" 10 | 11 | @implementation CWPriorityQueueModel 12 | 13 | - (instancetype)initWithName:(NSString *)name age:(NSInteger)age dateStr:(NSString *)dateStr 14 | { 15 | if (self = [super init]) { 16 | self.name = name; 17 | self.age = age; 18 | self.dateStr = dateStr; 19 | } 20 | return self; 21 | } 22 | 23 | - (NSString *)description 24 | { 25 | 26 | return [NSString stringWithFormat:@"%@_%ld date:%@",self.name,self.age,self.dateStr]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 16-前缀树(Trie).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 16-前缀树(Trie).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/16-前缀树(Trie)/16-前缀树(Trie)/CWTrie.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTrie.h 3 | // 16-前缀树(Trie) 4 | // 5 | // Created by 程金伟 on 2019/7/6. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWTrie : NSObject 12 | 13 | @property(nonatomic,assign)int size; 14 | 15 | - (instancetype)initWithParent:(CWTrie *)parent; 16 | 17 | /** 18 | 1、前缀树添加元素 19 | */ 20 | - (id)addKey:(NSString *)key value:(NSString *)value; 21 | 22 | /** 23 | 2、前缀树删除元素 24 | */ 25 | - (id)delectKey:(NSString *)key; 26 | 27 | /** 28 | 3、是否以某个前缀字符串开头 29 | */ 30 | - (BOOL)starWithStr:(NSString *)prefix; 31 | 32 | /** 33 | 4、是否包含某个字符串 34 | */ 35 | - (BOOL)contains:(NSString *)str; 36 | 37 | /** 38 | 5、前缀树的size 39 | */ 40 | - (int)trie_size; 41 | 42 | /** 43 | 6、前缀树是否为空 44 | */ 45 | - (BOOL)trie_isEmpty; 46 | 47 | /** 48 | 7、前缀树的的清空 49 | */ 50 | - (void)trie_clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Structures/17-并查集(UnionFind)/17-并查集(UnionFind).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/17-并查集(UnionFind)/17-并查集(UnionFind).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/17-并查集(UnionFind)/17-并查集(UnionFind).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/17-并查集(UnionFind)/17-并查集(UnionFind).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/17-并查集(UnionFind)/17-并查集(UnionFind).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 17-并查集(UnionFind).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/17-并查集(UnionFind)/17-并查集(UnionFind)/CWGoodUnionFind.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWGoodUnionFind.h 3 | // 16-并查集(UnionFind) 4 | // 5 | // Created by 程金伟 on 2019/10/19. 6 | // Copyright © 2019 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | @class CWItem; 11 | @interface CWGoodUnionFind : NSObject 12 | @property (nonatomic,assign) int count; 13 | @property (nonatomic,strong) NSMutableDictionary *dicItems; 14 | // 初始化配置 15 | - (instancetype)initWithSetCount:(int)count; 16 | // 1、并查集的效率较好的实现方法(基于路径减半方法) 17 | - (CWItem *)findSet:(NSString *)value; 18 | - (void)unionSet:(NSString *)value1 value2:(NSString *)value2; 19 | - (BOOL)isSameSet:(NSString *)value1 value2:(NSString *)value2; 20 | 21 | @end 22 | 23 | 24 | @interface CWItem:NSObject 25 | // 可以考虑使用数组,但是进行赋值的时候需要对index进行特殊处理,不能覆盖。 26 | @property(nonatomic,strong)CWItem *parent; 27 | @property(nonatomic,copy)NSString *value; 28 | @property(nonatomic,assign)NSInteger rank; 29 | @property(nonatomic,copy)NSString *name; 30 | @end 31 | 32 | 33 | -------------------------------------------------------------------------------- /Structures/17-并查集(UnionFind)/17-并查集(UnionFind)/CWTimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWTimeTool.h 3 | // 01-复杂度 4 | // 5 | // Created by mac on 2019/5/8. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef void(^ExecuteBlock)(void); 12 | 13 | @interface CWTimeTool : NSObject 14 | // 1、 执行任务消耗的时间( task consume ) 15 | - (void)executeTimesForFunction:(ExecuteBlock)block; 16 | @property (nonatomic,copy) ExecuteBlock block; 17 | 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/18-图(Graph)/18-图(Graph).xcodeproj/project.xcworkspace/xcuserdata/chengjinwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jinweicheng/OC_Algorithms_Structures/b24fb106db0cc20c8ff4200584f1c5e435d94a5c/Structures/18-图(Graph)/18-图(Graph).xcodeproj/project.xcworkspace/xcuserdata/mac.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/xcuserdata/chengjinwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 18-图(Graph).xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/xcuserdata/mac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph).xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 18-图(Graph).xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph)/CWQueueList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWQueueList.h 3 | // 07-队列 4 | // 5 | // Created by mac on 2019/5/16. 6 | // Copyright © 2019年 mac. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | /** 12 | 队列特点:只能在队列尾添加、队列头删除元素 13 | **/ 14 | 15 | @interface CWQueueList : NSObject 16 | 17 | /**< 链表子节点数目 */ 18 | @property (nonatomic,assign) int size; 19 | /**< 队列元素 */ 20 | @property (nonatomic,copy) id ele; 21 | 22 | /** 23 | 1、入队(队尾入) 24 | */ 25 | - (void)cw_enQueue:(id)E; 26 | 27 | /** 28 | 2、出队(队头出) 29 | */ 30 | - (id)cw_deQueue; 31 | 32 | /** 33 | 3、出队(队头元素) 34 | */ 35 | - (id)cw_topQueue; 36 | 37 | /** 38 | 4、队列的大小 39 | */ 40 | - (int)cw_size; 41 | 42 | /** 43 | 5、队列是否为空 44 | */ 45 | - (BOOL)cw_isEmpty; 46 | 47 | /** 48 | 6、清空队列数据 49 | */ 50 | - (void)cw_clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph)/CWStackList.h: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.h 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CWStackList : NSObject 12 | 13 | @property (nonatomic,assign) int size; /**< 数组size */ 14 | 15 | /** 16 | 1、数组的大小 17 | */ 18 | - (int)cw_size; 19 | 20 | /** 21 | 2、数组是否为空 22 | */ 23 | - (BOOL)cw_isEmpty; 24 | 25 | /** 26 | 3、新增某元素 27 | */ 28 | - (void)cw_push:(id)E; 29 | 30 | /** 31 | 4、新增某元素 32 | */ 33 | - (id)cw_pop; 34 | 35 | /** 36 | 5、新增某元素 37 | */ 38 | - (id)cw_top; 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /Structures/18-图(Graph)/18-图(Graph)/CWStackList.m: -------------------------------------------------------------------------------- 1 | // 2 | // CWStackList.m 3 | // 06-栈 4 | // 5 | // Created by 程金伟 on 2019/5/15. 6 | // Copyright © 2019年 cjw. All rights reserved. 7 | // 8 | 9 | #import "CWStackList.h" 10 | 11 | @interface CWStackList() 12 | @property (nonatomic,strong) NSMutableArray *array; /**< 数组 */ 13 | @end 14 | 15 | @implementation CWStackList 16 | 17 | - (instancetype)init{ 18 | if (self = [super init]) { 19 | self.array = [NSMutableArray array]; 20 | self.size = 0; 21 | } 22 | return self; 23 | } 24 | 25 | /** 26 | 1、数组的大小 27 | */ 28 | - (int)cw_size 29 | { 30 | return self.size; 31 | } 32 | 33 | /** 34 | 2、数组是否为空 35 | */ 36 | - (BOOL)cw_isEmpty 37 | { 38 | return self.size == 0; 39 | } 40 | 41 | /** 42 | 3、新增某元素 43 | */ 44 | - (void)cw_push:(id)E 45 | { 46 | [self.array addObject:E]; 47 | self.size++; 48 | } 49 | 50 | /** 51 | 4、新增某元素 52 | */ 53 | - (id)cw_pop 54 | { 55 | id object = self.array[self.size-1]; 56 | [self.array removeObjectAtIndex:self.size-1]; 57 | self.size--; 58 | return object; 59 | } 60 | 61 | /** 62 | 5、新增某元素 63 | */ 64 | - (id)cw_top 65 | { 66 | id object = self.array[self.size-1]; 67 | return object; 68 | } 69 | 70 | 71 | @end 72 | --------------------------------------------------------------------------------