├── 01_AlgorithmComplex ├── AlgorithmComplex_1.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ ├── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── cs.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ ├── chenshuang.xcuserdatad │ │ └── xcschemes │ │ │ └── xcschememanagement.plist │ │ └── cs.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── AlgorithmComplex_1 │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── TimeTool.h │ ├── TimeTool.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 02_ArrayList ├── 03_LinkedList.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03_LinkedList │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── LinkList │ ├── AbstractList.h │ ├── AbstractList.m │ ├── ArrayList.h │ ├── ArrayList.m │ ├── DoubleCircleLinkedList.h │ ├── DoubleCircleLinkedList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── SingleCircleLinkedList.h │ └── SingleCircleLinkedList.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 03_LinkedList ├── 03_LinkedList.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03_LinkedList │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── LinkList │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ └── List.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 04_LinkedListDemo ├── 03_LinkedList.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03_LinkedList │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── LinkList │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ └── List.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 05_DoubleLinkList ├── 03_LinkedList.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03_LinkedList │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── LinkList │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ └── List.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 06_CircleLinkList ├── 03_LinkedList.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03_LinkedList │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── LinkList │ ├── AbstractList.h │ ├── AbstractList.m │ ├── DoubleCircleLinkedList.h │ ├── DoubleCircleLinkedList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── SingleCircleLinkedList.h │ └── SingleCircleLinkedList.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 07_Stack ├── 03_LinkedList.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03_LinkedList │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── LinkList │ ├── AbstractList.h │ ├── AbstractList.m │ ├── ArrayList.h │ ├── ArrayList.m │ ├── DoubleCircleLinkedList.h │ ├── DoubleCircleLinkedList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── SingleCircleLinkedList.h │ ├── SingleCircleLinkedList.m │ ├── Stack.h │ └── Stack.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 08_Queue ├── 03_LinkedList.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 03_LinkedList │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── LinkList │ ├── AbstractList.h │ ├── AbstractList.m │ ├── ArrayList.h │ ├── ArrayList.m │ ├── CircleDeque.h │ ├── CircleDeque.m │ ├── CircleQueue.h │ ├── CircleQueue.m │ ├── Deque.h │ ├── Deque.m │ ├── DoubleCircleLinkedList.h │ ├── DoubleCircleLinkedList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ ├── Queue.m │ ├── QueueStack.h │ ├── QueueStack.m │ ├── SingleCircleLinkedList.h │ ├── SingleCircleLinkedList.m │ ├── Stack.h │ └── Stack.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 09_Tree ├── 09_Tree.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist ├── 09_Tree │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── Tree │ │ ├── BinarySearchTree.h │ │ ├── BinarySearchTree.m │ │ ├── TreeNode.h │ │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m ├── 10_BST ├── 09_Tree.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist ├── 09_Tree │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── Tree │ │ ├── BST.h │ │ ├── BST.m │ │ ├── BinarySearchTree.h │ │ ├── BinarySearchTree.m │ │ ├── TreeNode.h │ │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m ├── 11_AVLTree ├── 09_Tree.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist ├── 09_Tree │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── Info.plist │ ├── Tree │ │ ├── AVLNode.h │ │ ├── AVLNode.m │ │ ├── AVLTree.h │ │ ├── AVLTree.m │ │ ├── BBST.h │ │ ├── BBST.m │ │ ├── BST.h │ │ ├── BST.m │ │ ├── BinarySearchTree.h │ │ ├── BinarySearchTree.m │ │ ├── RBNode.h │ │ ├── RBNode.m │ │ ├── RBTree.h │ │ ├── RBTree.m │ │ ├── TreeNode.h │ │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m ├── 12_RedBlackTree ├── 12_RedBlackTree.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 12_RedBlackTree │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m │ ├── Tree │ ├── AVLNode.h │ ├── AVLNode.m │ ├── AVLTree.h │ ├── AVLTree.m │ ├── BBST.h │ ├── BBST.m │ ├── BST.h │ ├── BST.m │ ├── BinarySearchTree.h │ ├── BinarySearchTree.m │ ├── RBNode.h │ ├── RBNode.m │ ├── RBTree.h │ ├── RBTree.m │ ├── TreeNode.h │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 13_Set ├── 13_Set.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 13_Set │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m │ ├── Set │ ├── ListSet.h │ ├── ListSet.m │ ├── Set.h │ ├── Set.m │ ├── TreeSet.h │ └── TreeSet.m │ ├── Tree │ ├── AVLNode.h │ ├── AVLNode.m │ ├── AVLTree.h │ ├── AVLTree.m │ ├── BBST.h │ ├── BBST.m │ ├── BST.h │ ├── BST.m │ ├── BinarySearchTree.h │ ├── BinarySearchTree.m │ ├── RBNode.h │ ├── RBNode.m │ ├── RBTree.h │ ├── RBTree.m │ ├── TreeNode.h │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ ├── main.m │ └── test.txt ├── 14_Map ├── 14_Map.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 14_Map │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m │ ├── Map │ ├── Map.h │ ├── Map.m │ ├── TreeMap.h │ └── TreeMap.m │ ├── Tree │ ├── AVLNode.h │ ├── AVLNode.m │ ├── AVLTree.h │ ├── AVLTree.m │ ├── BBST.h │ ├── BBST.m │ ├── BST.h │ ├── BST.m │ ├── BinarySearchTree.h │ ├── BinarySearchTree.m │ ├── RBNode.h │ ├── RBNode.m │ ├── RBTree.h │ ├── RBTree.m │ ├── TreeNode.h │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 15_HashMap ├── 15_HashMap.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 15_HashMap │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m │ ├── Map │ ├── HashMap.h │ ├── HashMap.m │ ├── Map.h │ ├── Map.m │ ├── Node.h │ ├── Node.m │ ├── TreeMap.h │ └── TreeMap.m │ ├── Model │ ├── Person.h │ └── Person.m │ ├── Tree │ ├── AVLNode.h │ ├── AVLNode.m │ ├── AVLTree.h │ ├── AVLTree.m │ ├── BBST.h │ ├── BBST.m │ ├── BST.h │ ├── BST.m │ ├── BinarySearchTree.h │ ├── BinarySearchTree.m │ ├── RBNode.h │ ├── RBNode.m │ ├── RBTree.h │ ├── RBTree.m │ ├── TreeNode.h │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 16_Heap ├── 16_Heap.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 16_Heap │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Heap │ ├── AbstractHeap.h │ ├── AbstractHeap.m │ ├── BinaryHeap.h │ ├── BinaryHeap.m │ ├── Heap.h │ └── Heap.m │ ├── Info.plist │ ├── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m │ ├── Map │ ├── HashMap.h │ ├── HashMap.m │ ├── Map.h │ ├── Map.m │ ├── Node.h │ ├── Node.m │ ├── TreeMap.h │ └── TreeMap.m │ ├── Model │ ├── Person.h │ └── Person.m │ ├── Tree │ ├── AVLNode.h │ ├── AVLNode.m │ ├── AVLTree.h │ ├── AVLTree.m │ ├── BBST.h │ ├── BBST.m │ ├── BST.h │ ├── BST.m │ ├── BinarySearchTree.h │ ├── BinarySearchTree.m │ ├── RBNode.h │ ├── RBNode.m │ ├── RBTree.h │ ├── RBTree.m │ ├── TreeNode.h │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 17_PriorityQueue ├── 17_PriorityQueue.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 17_PriorityQueue │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Heap │ ├── AbstractHeap.h │ ├── AbstractHeap.m │ ├── BinaryHeap.h │ ├── BinaryHeap.m │ ├── Heap.h │ └── Heap.m │ ├── Info.plist │ ├── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m │ ├── Map │ ├── HashMap.h │ ├── HashMap.m │ ├── Map.h │ ├── Map.m │ ├── Node.h │ ├── Node.m │ ├── TreeMap.h │ └── TreeMap.m │ ├── Model │ ├── Person.h │ └── Person.m │ ├── PriorityQueue.h │ ├── PriorityQueue.m │ ├── Tree │ ├── AVLNode.h │ ├── AVLNode.m │ ├── AVLTree.h │ ├── AVLTree.m │ ├── BBST.h │ ├── BBST.m │ ├── BST.h │ ├── BST.m │ ├── BinarySearchTree.h │ ├── BinarySearchTree.m │ ├── RBNode.h │ ├── RBNode.m │ ├── RBTree.h │ ├── RBTree.m │ ├── TreeNode.h │ └── TreeNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── 19_Trie ├── 19_Trie.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── chenshuang.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── chenshuang.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── 19_Trie │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── List │ ├── AbstractList.h │ ├── AbstractList.m │ ├── LinkNode.h │ ├── LinkNode.m │ ├── LinkedList.h │ ├── LinkedList.m │ ├── List.h │ ├── List.m │ ├── Queue.h │ └── Queue.m │ ├── Map │ ├── Map.h │ ├── Map.m │ ├── TreeMap.h │ └── TreeMap.m │ ├── Tree │ ├── AVLNode.h │ ├── AVLNode.m │ ├── AVLTree.h │ ├── AVLTree.m │ ├── BBST.h │ ├── BBST.m │ ├── BST.h │ ├── BST.m │ ├── BinarySearchTree.h │ ├── BinarySearchTree.m │ ├── RBNode.h │ ├── RBNode.m │ ├── RBTree.h │ ├── RBTree.m │ ├── TreeNode.h │ └── TreeNode.m │ ├── Trie │ ├── Trie.h │ ├── Trie.m │ ├── TrieNode.h │ └── TrieNode.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── README.md /01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/project.xcworkspace/xcuserdata/cs.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/project.xcworkspace/xcuserdata/cs.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AlgorithmComplex_1.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1.xcodeproj/xcuserdata/cs.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AlgorithmComplex_1.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // AlgorithmComplex_1 4 | // 5 | // Created by chenshuang on 2019/4/22. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1/TimeTool.h: -------------------------------------------------------------------------------- 1 | // 2 | // TimeTool.h 3 | // AlgorithmComplex_1 4 | // 5 | // Created by chenshuang on 2019/4/23. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 时间工具类 14 | @interface TimeTool : NSObject 15 | 16 | /// 计算执行完 block 所需花费时间 17 | + (void)calculateTimeWithTitle:(NSString *)title operationBlock:(void(^)(void))operationBlock; 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // AlgorithmComplex_1 4 | // 5 | // Created by chenshuang on 2019/4/22. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /01_AlgorithmComplex/AlgorithmComplex_1/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // AlgorithmComplex_1 4 | // 5 | // Created by chenshuang on 2019/4/22. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/02_ArrayList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03_LinkedList.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/LinkList/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/LinkList/ArrayList.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArrayList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/12. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AbstractList.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | 可变数组 16 | */ 17 | @interface ArrayList : AbstractList 18 | 19 | /** 初始化 */ 20 | - (instancetype)initWithCapaticy:(int)capaticy; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/LinkList/DoubleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // DoubleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | /** 15 | 双向循环链表 16 | */ 17 | @interface DoubleCircleLinkedList : AbstractList 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/LinkList/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/LinkList/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/LinkList/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/LinkList/SingleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // SingleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /** 16 | 单向循环链表 17 | */ 18 | @interface SingleCircleLinkedList : AbstractList 19 | /** first*/ 20 | @property(nonatomic,strong)LinkNode *first; 21 | /** last*/ 22 | @property(nonatomic,strong)LinkNode *last; 23 | /** current*/ 24 | @property(nonatomic,strong)LinkNode *current; 25 | 26 | /** 27 | * 获取index位置对应的节点对象 28 | * @param index 29 | * @return 30 | */ 31 | - (LinkNode *)node:(NSUInteger)index; 32 | 33 | /// reset 34 | - (void)reset; 35 | 36 | /// 下一个 37 | - (id)next; 38 | 39 | /// remove 40 | - (id)remove; 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /02_ArrayList/03_LinkedList/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/03_LinkedList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03_LinkedList.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/LinkList/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/LinkList/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | 22 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/LinkList/LinkNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "LinkNode.h" 10 | 11 | @implementation LinkNode 12 | 13 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next { 14 | self = [super init]; 15 | if (self) { 16 | self.element = element; 17 | self.next = next; 18 | } 19 | return self; 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/LinkList/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | 21 | /** last*/ 22 | @property(nonatomic,strong)LinkNode *last; 23 | 24 | /** 25 | * 获取index位置对应的节点对象 26 | * @param index 27 | * @return 28 | */ 29 | - (LinkNode *)node:(NSUInteger)index; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/LinkList/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "LinkList/LinkedList.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | [self linkedListText]; 22 | } 23 | 24 | - (void)linkedListText { 25 | LinkedList *list = [[LinkedList alloc] init]; 26 | [list add:@20]; 27 | [list add:0 element:NULL]; 28 | [list add:@30]; 29 | [list add:[list size] element:@40]; 30 | [list remove:1]; 31 | NSLog(@"%@",list.description); 32 | 33 | [list clear]; 34 | NSLog(@"%@",list.description); 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /03_LinkedList/03_LinkedList/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/04_LinkedListDemo/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03_LinkedList.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/LinkList/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/LinkList/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | 22 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/LinkList/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | 21 | /** last*/ 22 | @property(nonatomic,strong)LinkNode *last; 23 | 24 | /** 25 | * 获取index位置对应的节点对象 26 | * @param index 27 | * @return 28 | */ 29 | - (LinkNode *)node:(NSUInteger)index; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/LinkList/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /04_LinkedListDemo/03_LinkedList/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/05_DoubleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03_LinkedList.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/LinkList/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/LinkList/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/LinkList/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/LinkList/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /05_DoubleLinkList/03_LinkedList/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/06_CircleLinkList/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03_LinkedList.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/LinkList/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/LinkList/DoubleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // DoubleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | /** 15 | 双向循环链表 16 | */ 17 | @interface DoubleCircleLinkedList : AbstractList 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/LinkList/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/LinkList/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/LinkList/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/LinkList/SingleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // SingleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /** 16 | 单向循环链表 17 | */ 18 | @interface SingleCircleLinkedList : AbstractList 19 | /** first*/ 20 | @property(nonatomic,strong)LinkNode *first; 21 | /** last*/ 22 | @property(nonatomic,strong)LinkNode *last; 23 | /** current*/ 24 | @property(nonatomic,strong)LinkNode *current; 25 | 26 | /** 27 | * 获取index位置对应的节点对象 28 | * @param index 29 | * @return 30 | */ 31 | - (LinkNode *)node:(NSUInteger)index; 32 | 33 | /// reset 34 | - (void)reset; 35 | 36 | /// 下一个 37 | - (id)next; 38 | 39 | /// remove 40 | - (id)remove; 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /06_CircleLinkList/03_LinkedList/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/07_Stack/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /07_Stack/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03_LinkedList.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/ArrayList.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArrayList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/12. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AbstractList.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | 可变数组 16 | */ 17 | @interface ArrayList : AbstractList 18 | 19 | /** 初始化 */ 20 | - (instancetype)initWithCapaticy:(int)capaticy; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/DoubleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // DoubleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | /** 15 | 双向循环链表 16 | */ 17 | @interface DoubleCircleLinkedList : AbstractList 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/SingleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // SingleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /** 16 | 单向循环链表 17 | */ 18 | @interface SingleCircleLinkedList : AbstractList 19 | /** first*/ 20 | @property(nonatomic,strong)LinkNode *first; 21 | /** last*/ 22 | @property(nonatomic,strong)LinkNode *last; 23 | /** current*/ 24 | @property(nonatomic,strong)LinkNode *current; 25 | 26 | /** 27 | * 获取index位置对应的节点对象 28 | * @param index 29 | * @return 30 | */ 31 | - (LinkNode *)node:(NSUInteger)index; 32 | 33 | /// reset 34 | - (void)reset; 35 | 36 | /// 下一个 37 | - (id)next; 38 | 39 | /// remove 40 | - (id)remove; 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/Stack.h: -------------------------------------------------------------------------------- 1 | // 2 | // Stack.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/12. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Stack : NSObject 14 | 15 | /// 长度 16 | - (int)size; 17 | 18 | /// 是否为空 19 | - (bool)isEmpty; 20 | 21 | /// 入栈 22 | - (void)push:(id)element; 23 | 24 | /// 出栈 25 | - (id)pop; 26 | 27 | /// 返回栈顶元素 28 | - (id)top; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/LinkList/Stack.m: -------------------------------------------------------------------------------- 1 | // 2 | // Stack.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/12. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Stack.h" 10 | #import "ArrayList.h" 11 | 12 | @implementation Stack { 13 | ArrayList *_arrayList; 14 | } 15 | 16 | - (instancetype)init { 17 | self = [super init]; 18 | if (self) { 19 | _arrayList = [[ArrayList alloc] init]; 20 | } 21 | return self; 22 | } 23 | 24 | /// 长度 25 | - (int)size { 26 | return [_arrayList size]; 27 | } 28 | 29 | /// 是否为空 30 | - (bool)isEmpty { 31 | return [_arrayList isEmpty]; 32 | } 33 | 34 | /// 入栈 35 | - (void)push:(id)element { 36 | [_arrayList add:element]; 37 | } 38 | 39 | /// 出栈 40 | - (id)pop { 41 | return [_arrayList remove:_arrayList.size - 1]; 42 | } 43 | 44 | /// 返回栈顶元素 45 | - (id)top { 46 | return [_arrayList get:_arrayList.size - 1]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /07_Stack/03_LinkedList/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/08_Queue/03_LinkedList.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /08_Queue/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 03_LinkedList.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/ArrayList.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArrayList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/12. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AbstractList.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | 可变数组 16 | */ 17 | @interface ArrayList : AbstractList 18 | 19 | /** 初始化 */ 20 | - (instancetype)initWithCapaticy:(int)capaticy; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/CircleDeque.h: -------------------------------------------------------------------------------- 1 | // 2 | // CircleDeque.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/14. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 循环双端队列 14 | */ 15 | @interface CircleDeque : NSObject 16 | 17 | /// 元素的数量 18 | - (int)size; 19 | 20 | /// 是否为空 21 | - (BOOL)isEmpty; 22 | 23 | /// 清空 24 | - (void)clear; 25 | 26 | /// 从后面入队 27 | - (void)enQueueRear:(id)element; 28 | 29 | /// 从后面出队 30 | - (id)deQueueRear; 31 | 32 | /// 从头部入队 33 | - (void)enQueueFront:(id)element; 34 | 35 | /// 从头部出队 36 | - (id)deQueueFront; 37 | 38 | /// 获取队列的头元素 39 | - (id)front; 40 | 41 | /// 获取队列的尾元素 42 | - (id)rear; 43 | 44 | @end 45 | 46 | NS_ASSUME_NONNULL_END 47 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/CircleQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // CircleQueue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/14. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 循环队列 14 | */ 15 | @interface CircleQueue : NSObject 16 | 17 | /// 元素的数量 18 | - (int)size; 19 | 20 | /// 是否为空 21 | - (BOOL)isEmpty; 22 | 23 | /// 清空 24 | - (void)clear; 25 | 26 | /// 入队 27 | - (void)enQueue:(id)element; 28 | 29 | /// 出队 30 | - (id)deQueue; 31 | 32 | /// 获取队列的头元素 33 | - (id)front; 34 | 35 | @end 36 | 37 | NS_ASSUME_NONNULL_END 38 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/Deque.h: -------------------------------------------------------------------------------- 1 | // 2 | // Deque.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/14. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 双端队列 14 | */ 15 | @interface Deque : NSObject 16 | 17 | /// 元素的数量 18 | - (int)size; 19 | 20 | /// 是否为空 21 | - (BOOL)isEmpty; 22 | 23 | /// 清空 24 | - (void)clear; 25 | 26 | /// 从后面入队 27 | - (void)enQueueRear:(id)element; 28 | 29 | /// 从后面出队 30 | - (id)deQueueRear; 31 | 32 | /// 从前面入队 33 | - (void)enQueueFront:(id)element; 34 | 35 | /// 从前面出队 36 | - (id)deQueueFront; 37 | 38 | /// 获取队列的头元素 39 | - (id)front; 40 | 41 | /// 获取队列的尾元素 42 | - (id)rear; 43 | 44 | @end 45 | 46 | NS_ASSUME_NONNULL_END 47 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/DoubleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // DoubleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | /** 15 | 双向循环链表 16 | */ 17 | @interface DoubleCircleLinkedList : AbstractList 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/QueueStack.h: -------------------------------------------------------------------------------- 1 | // 2 | // QueueStack.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 用栈实现队列操作 15 | */ 16 | @interface QueueStack : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/SingleCircleLinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // SingleCircleLinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/8. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /** 16 | 单向循环链表 17 | */ 18 | @interface SingleCircleLinkedList : AbstractList 19 | /** first*/ 20 | @property(nonatomic,strong)LinkNode *first; 21 | /** last*/ 22 | @property(nonatomic,strong)LinkNode *last; 23 | /** current*/ 24 | @property(nonatomic,strong)LinkNode *current; 25 | 26 | /** 27 | * 获取index位置对应的节点对象 28 | * @param index 29 | * @return 30 | */ 31 | - (LinkNode *)node:(NSUInteger)index; 32 | 33 | /// reset 34 | - (void)reset; 35 | 36 | /// 下一个 37 | - (id)next; 38 | 39 | /// remove 40 | - (id)remove; 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/Stack.h: -------------------------------------------------------------------------------- 1 | // 2 | // Stack.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/12. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Stack : NSObject 14 | 15 | /// 长度 16 | - (int)size; 17 | 18 | /// 是否为空 19 | - (bool)isEmpty; 20 | 21 | /// 入栈 22 | - (void)push:(id)element; 23 | 24 | /// 出栈 25 | - (id)pop; 26 | 27 | /// 返回栈顶元素 28 | - (id)top; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/LinkList/Stack.m: -------------------------------------------------------------------------------- 1 | // 2 | // Stack.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/12. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Stack.h" 10 | #import "ArrayList.h" 11 | 12 | @implementation Stack { 13 | ArrayList *_arrayList; 14 | } 15 | 16 | - (instancetype)init { 17 | self = [super init]; 18 | if (self) { 19 | _arrayList = [[ArrayList alloc] init]; 20 | } 21 | return self; 22 | } 23 | 24 | /// 长度 25 | - (int)size { 26 | return [_arrayList size]; 27 | } 28 | 29 | /// 是否为空 30 | - (bool)isEmpty { 31 | return [_arrayList isEmpty]; 32 | } 33 | 34 | /// 入栈 35 | - (void)push:(id)element { 36 | [_arrayList add:element]; 37 | } 38 | 39 | /// 出栈 40 | - (id)pop { 41 | return [_arrayList remove:_arrayList.size - 1]; 42 | } 43 | 44 | /// 返回栈顶元素 45 | - (id)top { 46 | return [_arrayList get:_arrayList.size - 1]; 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /08_Queue/03_LinkedList/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /09_Tree/09_Tree.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /09_Tree/09_Tree.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /09_Tree/09_Tree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/09_Tree/09_Tree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /09_Tree/09_Tree.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /09_Tree/09_Tree.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 09_Tree.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /09_Tree/09_Tree/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /09_Tree/09_Tree/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /09_Tree/09_Tree/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | @end 35 | 36 | NS_ASSUME_NONNULL_END 37 | -------------------------------------------------------------------------------- /09_Tree/09_Tree/Tree/TreeNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.m 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | @implementation TreeNode 12 | 13 | /** 初始化 */ 14 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent { 15 | self = [super init]; 16 | if (self) { 17 | self.element = element; 18 | self.parent = parent; 19 | } 20 | return self; 21 | } 22 | 23 | /** 是否是空树 */ 24 | - (BOOL)isLeaf { 25 | return self.left == nil && self.right == nil; 26 | } 27 | 28 | /** 是否有两个子树 */ 29 | - (BOOL)hasTwoChildren { 30 | return self.left != nil && self.right != nil; 31 | } 32 | 33 | - (NSString *)description { 34 | return [NSString stringWithFormat:@"%@",self.element]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /09_Tree/09_Tree/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /09_Tree/09_Tree/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /09_Tree/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /09_Tree/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /09_Tree/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /09_Tree/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /09_Tree/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /09_Tree/List/Queue.m: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Queue.h" 10 | #import "LinkedList.h" 11 | 12 | @implementation Queue { 13 | LinkedList *_linkList; 14 | } 15 | 16 | - (instancetype)init { 17 | self = [super init]; 18 | if (self) { 19 | _linkList = [[LinkedList alloc] init]; 20 | } 21 | return self; 22 | } 23 | 24 | /// 元素的数量 25 | - (int)size { 26 | return _linkList.size; 27 | } 28 | 29 | /// 是否为空 30 | - (BOOL)isEmpty { 31 | return [_linkList isEmpty]; 32 | } 33 | 34 | /// 清空 35 | - (void)clear { 36 | [_linkList clear]; 37 | } 38 | 39 | /// 入队 40 | - (void)enQueue:(id)element { 41 | [_linkList add:element]; 42 | } 43 | 44 | /// 出队 45 | - (id)deQueue { 46 | return [_linkList remove:0]; 47 | } 48 | 49 | /// 获取队列的头元素 50 | - (id)front { 51 | return [_linkList get:0]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /10_BST/09_Tree.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /10_BST/09_Tree.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /10_BST/09_Tree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/10_BST/09_Tree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /10_BST/09_Tree.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /10_BST/09_Tree.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 09_Tree.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /10_BST/09_Tree/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /10_BST/09_Tree/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /10_BST/09_Tree/Tree/BST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BST.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/21. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BinarySearchTree.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 二叉树搜索树 15 | */ 16 | @interface BST : BinarySearchTree 17 | 18 | /** 19 | * 清除所有元素 20 | */ 21 | - (void)clear; 22 | 23 | /** 24 | * 是否包含某个元素 25 | * @param element 26 | * @return bool 27 | */ 28 | - (bool)contains:(id)element; 29 | 30 | /** 31 | * 添加元素到尾部 32 | * @param element 33 | */ 34 | - (void)add:(id)element; 35 | 36 | /** 37 | * 删除元素 38 | * @param element 39 | */ 40 | - (void)remove:(id)element; 41 | 42 | @end 43 | 44 | NS_ASSUME_NONNULL_END 45 | -------------------------------------------------------------------------------- /10_BST/09_Tree/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | @end 35 | 36 | NS_ASSUME_NONNULL_END 37 | -------------------------------------------------------------------------------- /10_BST/09_Tree/Tree/TreeNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.m 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | @implementation TreeNode 12 | 13 | /** 初始化 */ 14 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent { 15 | self = [super init]; 16 | if (self) { 17 | self.element = element; 18 | self.parent = parent; 19 | } 20 | return self; 21 | } 22 | 23 | /** 是否是空树 */ 24 | - (BOOL)isLeaf { 25 | return self.left == nil && self.right == nil; 26 | } 27 | 28 | /** 是否有两个子树 */ 29 | - (BOOL)hasTwoChildren { 30 | return self.left != nil && self.right != nil; 31 | } 32 | 33 | - (NSString *)description { 34 | return [NSString stringWithFormat:@"%@",self.element]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /10_BST/09_Tree/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /10_BST/09_Tree/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /10_BST/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /10_BST/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /10_BST/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /10_BST/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /10_BST/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /10_BST/List/Queue.m: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Queue.h" 10 | #import "LinkedList.h" 11 | 12 | @implementation Queue { 13 | LinkedList *_linkList; 14 | } 15 | 16 | - (instancetype)init { 17 | self = [super init]; 18 | if (self) { 19 | _linkList = [[LinkedList alloc] init]; 20 | } 21 | return self; 22 | } 23 | 24 | /// 元素的数量 25 | - (int)size { 26 | return _linkList.size; 27 | } 28 | 29 | /// 是否为空 30 | - (BOOL)isEmpty { 31 | return [_linkList isEmpty]; 32 | } 33 | 34 | /// 清空 35 | - (void)clear { 36 | [_linkList clear]; 37 | } 38 | 39 | /// 入队 40 | - (void)enQueue:(id)element { 41 | [_linkList add:element]; 42 | } 43 | 44 | /// 出队 45 | - (id)deQueue { 46 | return [_linkList remove:0]; 47 | } 48 | 49 | /// 获取队列的头元素 50 | - (id)front { 51 | return [_linkList get:0]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/11_AVLTree/09_Tree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /11_AVLTree/09_Tree.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 09_Tree.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | /** 是否有左子树节点 */ 35 | - (BOOL)isLeftChild; 36 | 37 | /** 是否有右子树节点 */ 38 | - (BOOL)isRightChild; 39 | 40 | /// 返回叔父节点 41 | - (TreeNode *)sibling; 42 | 43 | @end 44 | 45 | NS_ASSUME_NONNULL_END 46 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /11_AVLTree/09_Tree/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/15. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /11_AVLTree/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /11_AVLTree/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /11_AVLTree/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /11_AVLTree/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /11_AVLTree/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/12_RedBlackTree/12_RedBlackTree.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 12_RedBlackTree.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /12_RedBlackTree/12_RedBlackTree/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /13_Set/13_Set.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /13_Set/13_Set.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /13_Set/13_Set.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/13_Set/13_Set.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /13_Set/13_Set.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /13_Set/13_Set.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 13_Set.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /13_Set/13_Set/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 13_Set 4 | // 5 | // Created by chenshuang on 2020/2/26. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /13_Set/13_Set/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /13_Set/13_Set/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /13_Set/13_Set/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /13_Set/13_Set/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /13_Set/13_Set/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /13_Set/13_Set/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /13_Set/13_Set/Set/ListSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // ListSet.h 3 | // 13_Set 4 | // 5 | // Created by chenshuang on 2020/2/26. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Set.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface ListSet : Set 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /13_Set/13_Set/Set/Set.h: -------------------------------------------------------------------------------- 1 | // 2 | // Set.h 3 | // 13_Set 4 | // 5 | // Created by chenshuang on 2020/2/26. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Set : NSObject 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)clear; 20 | 21 | - (BOOL)contains:(id)element; 22 | 23 | - (void)add:(id)element; 24 | 25 | - (void)remove:(id)element; 26 | 27 | - (void)traversal; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /13_Set/13_Set/Set/Set.m: -------------------------------------------------------------------------------- 1 | // 2 | // Set.m 3 | // 13_Set 4 | // 5 | // Created by chenshuang on 2020/2/26. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Set.h" 10 | 11 | @implementation Set 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /13_Set/13_Set/Set/TreeSet.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeSet.h 3 | // 13_Set 4 | // 5 | // Created by chenshuang on 2020/2/26. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Set.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface TreeSet : Set 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/BST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BST.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/21. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BinarySearchTree.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 二叉树搜索树 15 | */ 16 | @interface BST : BinarySearchTree 17 | 18 | /** 初始化 */ 19 | - (TreeNode *)createNode:(id)element parent:(TreeNode *)parent; 20 | 21 | /** 22 | * 清除所有元素 23 | */ 24 | - (void)clear; 25 | 26 | /** 27 | * 是否包含某个元素 28 | * @param element 29 | * @return bool 30 | */ 31 | - (bool)contains:(id)element; 32 | 33 | /** 34 | * 添加元素到尾部 35 | * @param element 36 | */ 37 | - (void)add:(id)element; 38 | 39 | /** 40 | * 删除元素 41 | * @param element 42 | */ 43 | - (void)remove:(id)element; 44 | 45 | #pragma mark - 平衡二叉树 46 | 47 | /** 添加节点后平衡二叉树 */ 48 | - (void)afterAdd:(TreeNode *)node; 49 | 50 | /** 删除节点后平衡二叉树 */ 51 | - (void)afterRemove:(TreeNode *)node; 52 | 53 | @end 54 | 55 | NS_ASSUME_NONNULL_END 56 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /13_Set/13_Set/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | /** 是否有左子树节点 */ 35 | - (BOOL)isLeftChild; 36 | 37 | /** 是否有右子树节点 */ 38 | - (BOOL)isRightChild; 39 | 40 | /// 返回叔父节点 41 | - (TreeNode *)sibling; 42 | 43 | @end 44 | 45 | NS_ASSUME_NONNULL_END 46 | -------------------------------------------------------------------------------- /13_Set/13_Set/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 13_Set 4 | // 5 | // Created by chenshuang on 2020/2/26. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /13_Set/13_Set/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 13_Set 4 | // 5 | // Created by chenshuang on 2020/2/26. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /14_Map/14_Map.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /14_Map/14_Map.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /14_Map/14_Map.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/14_Map/14_Map.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /14_Map/14_Map.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 14_Map.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /14_Map/14_Map/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /14_Map/14_Map/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /14_Map/14_Map/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /14_Map/14_Map/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /14_Map/14_Map/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /14_Map/14_Map/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /14_Map/14_Map/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /14_Map/14_Map/Map/Map.h: -------------------------------------------------------------------------------- 1 | // 2 | // Map.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Map : NSObject 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)put:(id)key value:(id)value; 20 | 21 | - (void)get:(id)key; 22 | 23 | - (void)remove; 24 | 25 | - (BOOL)containsKey:(id)key; 26 | 27 | - (BOOL)containsValue:(id)value; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /14_Map/14_Map/Map/Map.m: -------------------------------------------------------------------------------- 1 | // 2 | // Map.m 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | @implementation Map 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /14_Map/14_Map/Map/TreeMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeMap.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface TreeMap : Map 14 | 15 | - (void)traversal; 16 | 17 | @end 18 | 19 | NS_ASSUME_NONNULL_END 20 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/BST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BST.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/21. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BinarySearchTree.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 二叉树搜索树 15 | */ 16 | @interface BST : BinarySearchTree 17 | 18 | /** 初始化 */ 19 | - (TreeNode *)createNode:(id)element parent:(TreeNode *)parent; 20 | 21 | /** 22 | * 清除所有元素 23 | */ 24 | - (void)clear; 25 | 26 | /** 27 | * 是否包含某个元素 28 | * @param element 29 | * @return bool 30 | */ 31 | - (bool)contains:(id)element; 32 | 33 | /** 34 | * 添加元素到尾部 35 | * @param element 36 | */ 37 | - (void)add:(id)element; 38 | 39 | /** 40 | * 删除元素 41 | * @param element 42 | */ 43 | - (void)remove:(id)element; 44 | 45 | #pragma mark - 平衡二叉树 46 | 47 | /** 添加节点后平衡二叉树 */ 48 | - (void)afterAdd:(TreeNode *)node; 49 | 50 | /** 删除节点后平衡二叉树 */ 51 | - (void)afterRemove:(TreeNode *)node; 52 | 53 | @end 54 | 55 | NS_ASSUME_NONNULL_END 56 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /14_Map/14_Map/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | /** 是否有左子树节点 */ 35 | - (BOOL)isLeftChild; 36 | 37 | /** 是否有右子树节点 */ 38 | - (BOOL)isRightChild; 39 | 40 | /// 返回叔父节点 41 | - (TreeNode *)sibling; 42 | 43 | @end 44 | 45 | NS_ASSUME_NONNULL_END 46 | -------------------------------------------------------------------------------- /14_Map/14_Map/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /14_Map/14_Map/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "TreeMap.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | [self test1]; 22 | } 23 | 24 | - (void)test1 { 25 | TreeMap *map = [[TreeMap alloc] init]; 26 | [map put:@"c" value:@2]; 27 | [map put:@"a" value:@5]; 28 | [map put:@"b" value:@6]; 29 | [map put:@"a" value:@8]; 30 | 31 | [map traversal]; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /14_Map/14_Map/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/15_HashMap/15_HashMap.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /15_HashMap/15_HashMap.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 15_HashMap.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/1. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Map/HashMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // HashMap.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/1. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface HashMap : Map 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Map/Map.h: -------------------------------------------------------------------------------- 1 | // 2 | // Map.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Map : NSObject 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)put:(id)key value:(id)value; 20 | 21 | - (void)get:(id)key; 22 | 23 | - (void)remove; 24 | 25 | - (BOOL)containsKey:(id)key; 26 | 27 | - (BOOL)containsValue:(id)value; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Map/Map.m: -------------------------------------------------------------------------------- 1 | // 2 | // Map.m 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | @implementation Map 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Map/TreeMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeMap.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface TreeMap : Map 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)clear; 20 | 21 | - (void)put:(id)key value:(id)value; 22 | 23 | - (id)get:(id)key; 24 | 25 | - (BOOL)containsKey:(id)key; 26 | 27 | - (BOOL)containsValue:(id)value; 28 | 29 | - (void)traversal; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Model/Person.h: -------------------------------------------------------------------------------- 1 | // 2 | // Person.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Person : NSObject 14 | /** age */ 15 | @property(nonatomic,assign)int age; 16 | /** height */ 17 | @property(nonatomic,assign)float height; 18 | /** name */ 19 | @property(nonatomic,strong)NSString *name; 20 | 21 | /// 初始化 22 | - (instancetype)initWithAge:(int)age height:(float)height name:(NSString *)name; 23 | 24 | /// 用来比较两个对象是否相对 25 | - (BOOL)equals:(id)obj; 26 | 27 | /// hash code 28 | - (int)hasCode; 29 | 30 | /// 年龄比较 31 | - (int)compartTo:(Person *)per; 32 | 33 | @end 34 | 35 | NS_ASSUME_NONNULL_END 36 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | /** 是否有左子树节点 */ 35 | - (BOOL)isLeftChild; 36 | 37 | /** 是否有右子树节点 */ 38 | - (BOOL)isRightChild; 39 | 40 | /// 返回叔父节点 41 | - (TreeNode *)sibling; 42 | 43 | @end 44 | 45 | NS_ASSUME_NONNULL_END 46 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/1. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/1. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /15_HashMap/15_HashMap/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/1. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /16_Heap/16_Heap.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /16_Heap/16_Heap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /16_Heap/16_Heap.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/16_Heap/16_Heap.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /16_Heap/16_Heap.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /16_Heap/16_Heap.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 16_Heap.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /16_Heap/16_Heap/Heap/AbstractHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractHeap.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Heap.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface AbstractHeap : Heap 14 | 15 | /** int */ 16 | @property(nonatomic,assign)NSInteger size; 17 | 18 | /// 比较 num1 和 num2的大小 19 | - (int)compare:(NSNumber *)num1 num2:(NSNumber *)num2; 20 | 21 | // 返回根节点所在的索引 22 | - (int)root; 23 | 24 | // 返回左子节点的索引 25 | - (int)left:(int)node; 26 | 27 | // 返回右子节点的索引 28 | - (int)right:(int)node; 29 | 30 | // 返回对应索引的value 31 | - (NSNumber *)string:(int)node; 32 | 33 | @end 34 | 35 | NS_ASSUME_NONNULL_END 36 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Heap/AbstractHeap.m: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractHeap.m 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "AbstractHeap.h" 10 | 11 | @implementation AbstractHeap 12 | 13 | - (bool)isEmpty { 14 | return _size == 0; 15 | } 16 | 17 | - (int)compare:(NSNumber *)num1 num2:(NSNumber *)num2 { 18 | return num1.intValue - num2.intValue; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Heap/BinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // BinaryHeap.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "AbstractHeap.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol BinaryHeapDelegate 14 | 15 | - (int)compare:(NSNumber *)num1 num2:(NSNumber *)num2; 16 | 17 | @end 18 | 19 | /// 二叉堆(最大堆) 20 | @interface BinaryHeap : AbstractHeap 21 | 22 | /** delegate */ 23 | @property (nonatomic,weak) id delegate; 24 | 25 | - (void)print; 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Heap/Heap.h: -------------------------------------------------------------------------------- 1 | // 2 | // Heap.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Heap : NSObject 14 | // 元素的数量 15 | - (int)size; 16 | // 是否为空 17 | - (bool)isEmpty; 18 | // 清空 19 | - (void)clear; 20 | // 添加元素 21 | - (void)add:(id)element; 22 | // 获得堆顶元素 23 | - (id)get; 24 | // 删除堆顶元素 25 | - (id)remove; 26 | // 删除堆顶元素的同时插入一个新元素 27 | - (id)replace:(id)element; 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Heap/Heap.m: -------------------------------------------------------------------------------- 1 | // 2 | // Heap.m 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Heap.h" 10 | 11 | @implementation Heap 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Map/HashMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // HashMap.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/1. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface HashMap : Map 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Map/Map.h: -------------------------------------------------------------------------------- 1 | // 2 | // Map.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Map : NSObject 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)put:(id)key value:(id)value; 20 | 21 | - (void)get:(id)key; 22 | 23 | - (void)remove; 24 | 25 | - (BOOL)containsKey:(id)key; 26 | 27 | - (BOOL)containsValue:(id)value; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Map/Map.m: -------------------------------------------------------------------------------- 1 | // 2 | // Map.m 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | @implementation Map 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Map/TreeMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeMap.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface TreeMap : Map 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)clear; 20 | 21 | - (void)put:(id)key value:(id)value; 22 | 23 | - (id)get:(id)key; 24 | 25 | - (BOOL)containsKey:(id)key; 26 | 27 | - (BOOL)containsValue:(id)value; 28 | 29 | - (void)traversal; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Model/Person.h: -------------------------------------------------------------------------------- 1 | // 2 | // Person.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Person : NSObject 14 | /** age */ 15 | @property(nonatomic,assign)int age; 16 | /** height */ 17 | @property(nonatomic,assign)float height; 18 | /** name */ 19 | @property(nonatomic,strong)NSString *name; 20 | 21 | /// 初始化 22 | - (instancetype)initWithAge:(int)age height:(float)height name:(NSString *)name; 23 | 24 | /// 用来比较两个对象是否相对 25 | - (BOOL)equals:(id)obj; 26 | 27 | /// hash code 28 | - (int)hasCode; 29 | 30 | /// 年龄比较 31 | - (int)compartTo:(Person *)per; 32 | 33 | @end 34 | 35 | NS_ASSUME_NONNULL_END 36 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/BST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BST.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/21. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BinarySearchTree.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 二叉树搜索树 15 | */ 16 | @interface BST : BinarySearchTree 17 | 18 | /** 初始化 */ 19 | - (TreeNode *)createNode:(id)element parent:(TreeNode *)parent; 20 | 21 | /** 22 | * 清除所有元素 23 | */ 24 | - (void)clear; 25 | 26 | /** 27 | * 是否包含某个元素 28 | * @param element 29 | * @return bool 30 | */ 31 | - (bool)contains:(id)element; 32 | 33 | /** 34 | * 添加元素到尾部 35 | * @param element 36 | */ 37 | - (void)add:(id)element; 38 | 39 | /** 40 | * 删除元素 41 | * @param element 42 | */ 43 | - (void)remove:(id)element; 44 | 45 | #pragma mark - 平衡二叉树 46 | 47 | /** 添加节点后平衡二叉树 */ 48 | - (void)afterAdd:(TreeNode *)node; 49 | 50 | /** 删除节点后平衡二叉树 */ 51 | - (void)afterRemove:(TreeNode *)node; 52 | 53 | @end 54 | 55 | NS_ASSUME_NONNULL_END 56 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | /** 是否有左子树节点 */ 35 | - (BOOL)isLeftChild; 36 | 37 | /** 是否有右子树节点 */ 38 | - (BOOL)isRightChild; 39 | 40 | /// 返回叔父节点 41 | - (TreeNode *)sibling; 42 | 43 | @end 44 | 45 | NS_ASSUME_NONNULL_END 46 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /16_Heap/16_Heap/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/17_PriorityQueue/17_PriorityQueue.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 17_PriorityQueue.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 17_PriorityQueue 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Heap/AbstractHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractHeap.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Heap.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface AbstractHeap : Heap 14 | 15 | /** int */ 16 | @property(nonatomic,assign)NSInteger size; 17 | 18 | /// 比较 num1 和 num2的大小 19 | - (int)compare:(NSNumber *)num1 num2:(NSNumber *)num2; 20 | 21 | // 返回根节点所在的索引 22 | - (int)root; 23 | 24 | // 返回左子节点的索引 25 | - (int)left:(int)node; 26 | 27 | // 返回右子节点的索引 28 | - (int)right:(int)node; 29 | 30 | // 返回对应索引的value 31 | - (NSNumber *)string:(int)node; 32 | 33 | @end 34 | 35 | NS_ASSUME_NONNULL_END 36 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Heap/AbstractHeap.m: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractHeap.m 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "AbstractHeap.h" 10 | 11 | @implementation AbstractHeap 12 | 13 | - (bool)isEmpty { 14 | return _size == 0; 15 | } 16 | 17 | - (int)compare:(NSNumber *)num1 num2:(NSNumber *)num2 { 18 | return num1.intValue - num2.intValue; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Heap/BinaryHeap.h: -------------------------------------------------------------------------------- 1 | // 2 | // BinaryHeap.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "AbstractHeap.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @protocol BinaryHeapDelegate 14 | 15 | - (int)compare:(NSNumber *)num1 num2:(NSNumber *)num2; 16 | 17 | @end 18 | 19 | /// 二叉堆(最大堆) 20 | @interface BinaryHeap : AbstractHeap 21 | 22 | /** delegate */ 23 | @property (nonatomic,weak) id delegate; 24 | 25 | - (void)print; 26 | 27 | @end 28 | 29 | NS_ASSUME_NONNULL_END 30 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Heap/Heap.h: -------------------------------------------------------------------------------- 1 | // 2 | // Heap.h 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Heap : NSObject 14 | // 元素的数量 15 | - (int)size; 16 | // 是否为空 17 | - (bool)isEmpty; 18 | // 清空 19 | - (void)clear; 20 | // 添加元素 21 | - (void)add:(id)element; 22 | // 获得堆顶元素 23 | - (id)get; 24 | // 删除堆顶元素 25 | - (id)remove; 26 | // 删除堆顶元素的同时插入一个新元素 27 | - (id)replace:(id)element; 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Heap/Heap.m: -------------------------------------------------------------------------------- 1 | // 2 | // Heap.m 3 | // 16_Heap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Heap.h" 10 | 11 | @implementation Heap 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Map/HashMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // HashMap.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/1. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface HashMap : Map 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Map/Map.h: -------------------------------------------------------------------------------- 1 | // 2 | // Map.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Map : NSObject 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)put:(id)key value:(id)value; 20 | 21 | - (void)get:(id)key; 22 | 23 | - (void)remove; 24 | 25 | - (BOOL)containsKey:(id)key; 26 | 27 | - (BOOL)containsValue:(id)value; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Map/Map.m: -------------------------------------------------------------------------------- 1 | // 2 | // Map.m 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | @implementation Map 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Map/TreeMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeMap.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface TreeMap : Map 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)clear; 20 | 21 | - (void)put:(id)key value:(id)value; 22 | 23 | - (id)get:(id)key; 24 | 25 | - (BOOL)containsKey:(id)key; 26 | 27 | - (BOOL)containsValue:(id)value; 28 | 29 | - (void)traversal; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Model/Person.h: -------------------------------------------------------------------------------- 1 | // 2 | // Person.h 3 | // 15_HashMap 4 | // 5 | // Created by chenshuang on 2020/3/7. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Person : NSObject 14 | /** age */ 15 | @property(nonatomic,assign)int age; 16 | /** height */ 17 | @property(nonatomic,assign)float height; 18 | /** name */ 19 | @property(nonatomic,strong)NSString *name; 20 | 21 | /// 初始化 22 | - (instancetype)initWithAge:(int)age height:(float)height name:(NSString *)name; 23 | 24 | /// 用来比较两个对象是否相对 25 | - (BOOL)equals:(id)obj; 26 | 27 | /// hash code 28 | - (int)hasCode; 29 | 30 | /// 年龄比较 31 | - (int)compartTo:(Person *)per; 32 | 33 | @end 34 | 35 | NS_ASSUME_NONNULL_END 36 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/PriorityQueue.h: -------------------------------------------------------------------------------- 1 | // 2 | // PriorityQueue.h 3 | // 17_PriorityQueue 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Queue.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface PriorityQueue : Queue 14 | 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/PriorityQueue.m: -------------------------------------------------------------------------------- 1 | // 2 | // PriorityQueue.m 3 | // 17_PriorityQueue 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "PriorityQueue.h" 10 | #import "BinaryHeap.h" 11 | 12 | @implementation PriorityQueue { 13 | BinaryHeap *_heap; 14 | } 15 | 16 | - (instancetype)init { 17 | self = [super init]; 18 | if (self) { 19 | _heap = [[BinaryHeap alloc] init]; 20 | } 21 | return self; 22 | } 23 | 24 | - (int)size { 25 | return _heap.size; 26 | } 27 | 28 | - (BOOL)isEmpty { 29 | return _heap.isEmpty; 30 | } 31 | 32 | - (void)clear { 33 | [_heap clear]; 34 | } 35 | 36 | - (void)enQueue:(id)element { 37 | [_heap add:element]; 38 | } 39 | 40 | - (id)deQueue { 41 | return [_heap remove]; 42 | } 43 | 44 | - (id)front { 45 | return _heap.get; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 17_PriorityQueue 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /17_PriorityQueue/17_PriorityQueue/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 17_PriorityQueue 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /19_Trie/19_Trie.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /19_Trie/19_Trie.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /19_Trie/19_Trie.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenshuangsmart/DataConfigurationArithmeticDemo/c20a722d0e4a3a51b7250564d0e1cb08a9f8bc76/19_Trie/19_Trie.xcodeproj/project.xcworkspace/xcuserdata/chenshuang.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /19_Trie/19_Trie.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /19_Trie/19_Trie.xcodeproj/xcuserdata/chenshuang.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 19_Trie.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 19_Trie 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /19_Trie/19_Trie/List/AbstractList.h: -------------------------------------------------------------------------------- 1 | // 2 | // AbstractList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "List.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /// 链表 抽象基类 15 | @interface AbstractList : List 16 | 17 | /** size*/ 18 | @property(nonatomic,assign)NSUInteger size; 19 | 20 | /// 越界查询 21 | - (bool)rangeCheck:(NSUInteger)index; 22 | 23 | /// 添加元素越界检查 24 | - (bool)rangeCheckForAdd:(NSUInteger)index; 25 | 26 | @end 27 | 28 | NS_ASSUME_NONNULL_END 29 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/List/LinkNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkNode.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 链表节点 14 | @interface LinkNode : NSObject 15 | 16 | /** element*/ 17 | @property(nonatomic,assign)id element; 18 | 19 | /** next*/ 20 | @property(nonatomic,strong)LinkNode *next; 21 | /** next*/ 22 | @property(nonatomic,strong)LinkNode *prev; 23 | 24 | - (instancetype)initWithPrev:(LinkNode *)prev element:(id)element next:(LinkNode *)next; 25 | 26 | - (instancetype)initWithElement:(id)element next:(LinkNode *)next; 27 | 28 | @end 29 | 30 | NS_ASSUME_NONNULL_END 31 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/List/LinkedList.h: -------------------------------------------------------------------------------- 1 | // 2 | // LinkedList.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LinkNode.h" 11 | #import "AbstractList.h" 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | /// 链表 16 | @interface LinkedList : AbstractList 17 | 18 | /** first*/ 19 | @property(nonatomic,strong)LinkNode *first; 20 | /** last*/ 21 | @property(nonatomic,strong)LinkNode *last; 22 | /** current*/ 23 | @property(nonatomic,strong)LinkNode *current; 24 | 25 | /** 26 | * 获取index位置对应的节点对象 27 | * @param index 28 | * @return 29 | */ 30 | - (LinkNode *)node:(NSUInteger)index; 31 | 32 | /// reset 33 | - (void)reset; 34 | 35 | /// 下一个 36 | - (id)next; 37 | 38 | /// remove 39 | - (id)remove; 40 | 41 | @end 42 | 43 | NS_ASSUME_NONNULL_END 44 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/List/List.m: -------------------------------------------------------------------------------- 1 | // 2 | // List.m 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/4/28. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "List.h" 10 | 11 | @implementation List 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/List/Queue.h: -------------------------------------------------------------------------------- 1 | // 2 | // Queue.h 3 | // 03_LinkedList 4 | // 5 | // Created by chenshuang on 2019/5/13. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | 队列 15 | */ 16 | @interface Queue : NSObject 17 | 18 | /// 元素的数量 19 | - (int)size; 20 | 21 | /// 是否为空 22 | - (BOOL)isEmpty; 23 | 24 | /// 清空 25 | - (void)clear; 26 | 27 | /// 入队 28 | - (void)enQueue:(id)element; 29 | 30 | /// 出队 31 | - (id)deQueue; 32 | 33 | /// 获取队列的头元素 34 | - (id)front; 35 | 36 | @end 37 | 38 | NS_ASSUME_NONNULL_END 39 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Map/Map.h: -------------------------------------------------------------------------------- 1 | // 2 | // Map.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Map : NSObject 14 | 15 | - (int)size; 16 | 17 | - (BOOL)isEmpty; 18 | 19 | - (void)put:(id)key value:(id)value; 20 | 21 | - (id)get:(id)key; 22 | 23 | - (void)remove; 24 | 25 | - (void)clear; 26 | 27 | - (BOOL)containsKey:(id)key; 28 | 29 | - (BOOL)containsValue:(id)value; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Map/Map.m: -------------------------------------------------------------------------------- 1 | // 2 | // Map.m 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | @implementation Map 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Map/TreeMap.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeMap.h 3 | // 14_Map 4 | // 5 | // Created by chenshuang on 2020/2/29. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "Map.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface TreeMap : Map 14 | 15 | - (void)traversal; 16 | 17 | - (void)remove:(id)element; 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Tree/AVLNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /** 14 | AVL树节点 15 | */ 16 | @interface AVLNode : TreeNode 17 | 18 | /** int - 高度*/ 19 | @property(nonatomic,assign)int height; 20 | 21 | /** 平衡因子 */ 22 | - (int)balanceFactor; 23 | 24 | /** 更新高度 */ 25 | - (void)updateHeight; 26 | 27 | /** 返回节点数较多的节点 */ 28 | - (TreeNode *)tallerChild; 29 | 30 | @end 31 | 32 | NS_ASSUME_NONNULL_END 33 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Tree/AVLTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // AVLTree.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/26. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | #import "BBST.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | /** 15 | AVL树 16 | */ 17 | @interface AVLTree : BBST 18 | 19 | @end 20 | 21 | NS_ASSUME_NONNULL_END 22 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Tree/BBST.h: -------------------------------------------------------------------------------- 1 | // 2 | // BBST.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/11. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BST.h" 10 | 11 | @class AVLNode; 12 | 13 | NS_ASSUME_NONNULL_BEGIN 14 | 15 | @interface BBST : BST 16 | 17 | /** 左旋转 grand - 爷爷节点 */ 18 | - (void)rotateLeft:(AVLNode *)grand; 19 | 20 | /** 右旋转 */ 21 | - (void)rotateRight:(AVLNode *)grand; 22 | 23 | /** 更新节点*/ 24 | - (void)afterRotate:(TreeNode *)grand parent:(TreeNode *)parent child:(TreeNode *)child; 25 | 26 | /// 旋转操作 27 | - (void)rotate:(TreeNode *)r // 子树的根节点 28 | a:(TreeNode *)a b:(TreeNode *)b c:(TreeNode *)c 29 | d:(TreeNode *)d 30 | e:(TreeNode *)e f:(TreeNode *)f g:(TreeNode *)g; 31 | 32 | @end 33 | 34 | NS_ASSUME_NONNULL_END 35 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Tree/RBNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TreeNode.h" 10 | 11 | typedef enum : NSUInteger { 12 | Red = 0, 13 | Black = 1, 14 | } RBTreeNodeType; 15 | 16 | NS_ASSUME_NONNULL_BEGIN 17 | 18 | /// 红黑树节点 19 | @interface RBNode : TreeNode 20 | 21 | /** color type */ 22 | @property(nonatomic,assign)RBTreeNodeType color; 23 | 24 | @end 25 | 26 | NS_ASSUME_NONNULL_END 27 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Tree/RBNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // RBNode.m 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "RBNode.h" 10 | 11 | @implementation RBNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Tree/RBTree.h: -------------------------------------------------------------------------------- 1 | // 2 | // RBTree.h 3 | // 12_RedBlackTree 4 | // 5 | // Created by chenshuang on 2020/1/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "BBST.h" 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | /// 红黑树 14 | @interface RBTree : BBST 15 | 16 | @end 17 | 18 | NS_ASSUME_NONNULL_END 19 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Tree/TreeNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TreeNode.h 3 | // 09_Tree 4 | // 5 | // Created by chenshuang on 2019/5/19. 6 | // Copyright © 2019年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | /** 13 | 树节点 14 | */ 15 | @interface TreeNode : NSObject 16 | /** id*/ 17 | @property(nonatomic,strong)id element; 18 | /** left*/ 19 | @property(nonatomic,strong)TreeNode *left; 20 | /** right*/ 21 | @property(nonatomic,strong)TreeNode *right; 22 | /** parent*/ 23 | @property(nonatomic,strong)TreeNode *parent; 24 | 25 | /** 初始化 */ 26 | - (instancetype)initWithElement:(id)element parent:(TreeNode *)parent; 27 | 28 | /** 是否是空树 - 即叶子节点 */ 29 | - (BOOL)isLeaf; 30 | 31 | /** 是否有两个子树 */ 32 | - (BOOL)hasTwoChildren; 33 | 34 | /** 是否有左子树节点 */ 35 | - (BOOL)isLeftChild; 36 | 37 | /** 是否有右子树节点 */ 38 | - (BOOL)isRightChild; 39 | 40 | /// 返回叔父节点 41 | - (TreeNode *)sibling; 42 | 43 | @end 44 | 45 | NS_ASSUME_NONNULL_END 46 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Trie/Trie.h: -------------------------------------------------------------------------------- 1 | // 2 | // Trie.h 3 | // 19_Trie 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface Trie : NSObject 14 | 15 | - (int)size; 16 | 17 | - (bool)isEmpty; 18 | 19 | - (void)clear; 20 | 21 | - (NSString *)get:(NSString *)key; 22 | 23 | - (bool)contains:(NSString *)key; 24 | 25 | - (id)add:(NSString *)key value:(id)value; 26 | 27 | - (id)remove:(NSString *)key; 28 | 29 | - (bool)starsWith:(NSString *)prefix; 30 | 31 | @end 32 | 33 | NS_ASSUME_NONNULL_END 34 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Trie/TrieNode.h: -------------------------------------------------------------------------------- 1 | // 2 | // TrieNode.h 3 | // 19_Trie 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @class TreeMap; 14 | 15 | @interface TrieNode : NSObject 16 | 17 | @property(nonatomic,strong)TrieNode *parent; 18 | /** children */ 19 | @property(nonatomic,strong)TreeMap *children; 20 | /** character */ 21 | @property(nonatomic, strong)NSString *character; 22 | /** value */ 23 | @property(nonatomic,strong)id value; 24 | /** word 是否为单词的结尾(是否为一个完整的单词) */ 25 | @property(nonatomic,assign)BOOL word; 26 | 27 | - (instancetype)initWithParent:(TrieNode *)parent; 28 | 29 | @end 30 | 31 | NS_ASSUME_NONNULL_END 32 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/Trie/TrieNode.m: -------------------------------------------------------------------------------- 1 | // 2 | // TrieNode.m 3 | // 19_Trie 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "TrieNode.h" 10 | 11 | @implementation TrieNode 12 | 13 | - (instancetype)initWithParent:(TrieNode *)parent { 14 | self = [super init]; 15 | if (self) { 16 | self.parent = parent; 17 | } 18 | return self; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 19_Trie 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 19_Trie 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "Trie.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | [self test]; 21 | } 22 | 23 | - (void)test { 24 | Trie *trie = [[Trie alloc] init]; 25 | [trie add:@"cat" value:@(1)]; 26 | [trie add:@"dog" value:@(2)]; 27 | [trie add:@"catalog" value:@(3)]; 28 | [trie add:@"cast" value:@(4)]; 29 | 30 | NSString *prefix = @"cat"; 31 | // prefix = @"dog"; 32 | // prefix = @"catalog"; 33 | // prefix = @"cast"; 34 | 35 | NSLog(@"starsWith:%@ %d",prefix,[trie starsWith:prefix]); 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /19_Trie/19_Trie/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 19_Trie 4 | // 5 | // Created by chenshuang on 2020/3/14. 6 | // Copyright © 2020年 wenwen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | --------------------------------------------------------------------------------