├── .gitignore ├── Arr └── main.c ├── CC.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── herrylo.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── herrylo.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── img ├── WechatIMG453.png └── WechatIMG454.png ├── list └── main.c ├── poin ├── Malloc │ ├── malloc1.c │ └── malloc1.h ├── Pointer │ ├── pointer.c │ └── pointer.h ├── Struct │ ├── struct.c │ └── struct.h └── main.c ├── queue └── main.c ├── readme.md ├── stack └── main.c └── tree └── main.c /.gitignore: -------------------------------------------------------------------------------- 1 | CC.xcodeproj 2 | build 3 | .vscode 4 | -------------------------------------------------------------------------------- /Arr/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // list 4 | // 5 | // Created by HerryLo on 2019/10/20. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | // 线性结构:连续存储 数组 10 | #include 11 | #include 12 | #include 13 | 14 | bool a = 1; 15 | 16 | typedef struct ArrList { 17 | int *p; // 数组第一个元素的地址 18 | int len; // 数组长度 19 | int cnt; // 数组元素的有效长度 20 | }ArrList; //别名 ArrList 21 | 22 | // 初始化创建数组 23 | void arrInit(ArrList *arr, int length); 24 | // 添加(尾部) 25 | void append(ArrList *arr, int value); 26 | // 展示元素 27 | void show(ArrList *arr); 28 | // 插入 29 | void insert(ArrList *arr, int value, int index); 30 | // 删除 31 | void delet(ArrList); 32 | // 排序 33 | void sort(ArrList); 34 | 35 | // 判断是否空 36 | bool isEmpty(ArrList *arr); 37 | // 判断是否满 38 | bool isFull(ArrList *arr); 39 | 40 | int main() { 41 | ArrList arr; 42 | 43 | arrInit(&arr, 5); 44 | append(&arr, 1); 45 | append(&arr, 2); 46 | append(&arr, 3); 47 | insert(&arr, 99, 1); 48 | show(&arr); 49 | 50 | printf("数组长度为:%d\n", arr.len); 51 | printf("数组当前有效长度为:%d\n", arr.cnt); 52 | printf("数组中第一个元素的值:%d\n", *(arr.p)); 53 | return 0; 54 | } 55 | 56 | // 初始化数组 57 | void arrInit(ArrList *arr, int length) { 58 | arr->p = (int *)malloc(sizeof(int) * length); 59 | 60 | if(arr == NULL) 61 | printf("Array create fail"); 62 | else 63 | arr->len = length; 64 | arr->cnt = 0; 65 | } 66 | 67 | // 是否空 68 | bool isEmpty(ArrList *arr) { 69 | if(arr->cnt == 0) { 70 | return true; 71 | }else { 72 | return false; 73 | } 74 | } 75 | 76 | // 是否满 77 | bool isFull(ArrList *arr) { 78 | if(arr->cnt == arr->len) { 79 | return true; 80 | }else { 81 | return false; 82 | } 83 | } 84 | 85 | 86 | // append 87 | void append(ArrList *arr, int value){ 88 | if(isFull(arr)) { 89 | printf("数组已满, 已无法 append \n"); 90 | return; 91 | } 92 | 93 | arr->p[arr->cnt] = value; 94 | ++(arr->cnt); 95 | return; 96 | } 97 | 98 | // show 99 | void show(ArrList *arr) { 100 | int len = arr->cnt; 101 | 102 | if(isEmpty(arr)) { 103 | printf("数组为空\n"); 104 | return; 105 | } 106 | 107 | for (int i = 0; i< len; ++i) { 108 | printf("%d ", arr->p[i]); 109 | } 110 | printf("\n"); 111 | } 112 | 113 | //插入 114 | // arr 数组 115 | // value 数值 116 | // index 个数 117 | void insert(ArrList *arr, int value, int index) { 118 | if(isFull(arr)) { 119 | printf("数组已满, 已无法 insert \n"); 120 | return; 121 | } 122 | 123 | int len = arr->cnt; 124 | 125 | if(index < 1 || index > arr->cnt+1){ 126 | return; 127 | } 128 | 129 | for (int i = len-1; i>=index-1; --i) { 130 | arr->p[i+1] = arr->p[i]; 131 | } 132 | arr->p[index-1] = value; 133 | ++(arr->cnt); 134 | return; 135 | } 136 | 137 | 138 | -------------------------------------------------------------------------------- /CC.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5F3064D32414AE5100573500 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 5F3064D22414AE5100573500 /* main.c */; }; 11 | 5F6608E124027896008F7D0A /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 5F6608E024027896008F7D0A /* main.c */; }; 12 | 5FB8AC4C24ACF107003B162E /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 5FB8AC4B24ACF107003B162E /* main.c */; }; 13 | 5FB8D7C9237728B300373DC2 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 5FB8D7C8237728B300373DC2 /* main.c */; }; 14 | 5FF72A90235C9B1400EC8413 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 5FF72A8F235C9B1400EC8413 /* main.c */; }; 15 | 5FF72A9B235C9C8F00EC8413 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 5FF72A9A235C9C8F00EC8413 /* main.c */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXCopyFilesBuildPhase section */ 19 | 5F3064CE2414AE5100573500 /* CopyFiles */ = { 20 | isa = PBXCopyFilesBuildPhase; 21 | buildActionMask = 2147483647; 22 | dstPath = /usr/share/man/man1/; 23 | dstSubfolderSpec = 0; 24 | files = ( 25 | ); 26 | runOnlyForDeploymentPostprocessing = 1; 27 | }; 28 | 5F6608DC24027896008F7D0A /* CopyFiles */ = { 29 | isa = PBXCopyFilesBuildPhase; 30 | buildActionMask = 2147483647; 31 | dstPath = /usr/share/man/man1/; 32 | dstSubfolderSpec = 0; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 1; 36 | }; 37 | 5FB8AC4724ACF107003B162E /* CopyFiles */ = { 38 | isa = PBXCopyFilesBuildPhase; 39 | buildActionMask = 2147483647; 40 | dstPath = /usr/share/man/man1/; 41 | dstSubfolderSpec = 0; 42 | files = ( 43 | ); 44 | runOnlyForDeploymentPostprocessing = 1; 45 | }; 46 | 5FB8D7C4237728B300373DC2 /* CopyFiles */ = { 47 | isa = PBXCopyFilesBuildPhase; 48 | buildActionMask = 2147483647; 49 | dstPath = /usr/share/man/man1/; 50 | dstSubfolderSpec = 0; 51 | files = ( 52 | ); 53 | runOnlyForDeploymentPostprocessing = 1; 54 | }; 55 | 5FF72A8B235C9B1400EC8413 /* CopyFiles */ = { 56 | isa = PBXCopyFilesBuildPhase; 57 | buildActionMask = 2147483647; 58 | dstPath = /usr/share/man/man1/; 59 | dstSubfolderSpec = 0; 60 | files = ( 61 | ); 62 | runOnlyForDeploymentPostprocessing = 1; 63 | }; 64 | 5FF72A96235C9C8F00EC8413 /* CopyFiles */ = { 65 | isa = PBXCopyFilesBuildPhase; 66 | buildActionMask = 2147483647; 67 | dstPath = /usr/share/man/man1/; 68 | dstSubfolderSpec = 0; 69 | files = ( 70 | ); 71 | runOnlyForDeploymentPostprocessing = 1; 72 | }; 73 | /* End PBXCopyFilesBuildPhase section */ 74 | 75 | /* Begin PBXFileReference section */ 76 | 5F1C4335234F77E50034E743 /* pointer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = pointer.h; sourceTree = ""; }; 77 | 5F1C4336234F77E50034E743 /* pointer.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = pointer.c; sourceTree = ""; }; 78 | 5F1C433B234F788B0034E743 /* struct.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = struct.h; sourceTree = ""; }; 79 | 5F1C433C234F788B0034E743 /* struct.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = struct.c; sourceTree = ""; }; 80 | 5F3064D02414AE5100573500 /* stack */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = stack; sourceTree = BUILT_PRODUCTS_DIR; }; 81 | 5F3064D22414AE5100573500 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 82 | 5F51AAF723E95EC4002E3084 /* poin */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = poin; sourceTree = BUILT_PRODUCTS_DIR; }; 83 | 5F51AAF823E95EC4002E3084 /* list */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = list; sourceTree = BUILT_PRODUCTS_DIR; }; 84 | 5F51AAF923E95EC4002E3084 /* Arr */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Arr; sourceTree = BUILT_PRODUCTS_DIR; }; 85 | 5F6608DE24027896008F7D0A /* queue */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = queue; sourceTree = BUILT_PRODUCTS_DIR; }; 86 | 5F6608E024027896008F7D0A /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 87 | 5F7AAC7D23536F5400B876DF /* malloc1.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = malloc1.h; sourceTree = ""; }; 88 | 5F7AAC7E23536F5400B876DF /* malloc1.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = malloc1.c; sourceTree = ""; }; 89 | 5FB8AC4924ACF107003B162E /* tree */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = tree; sourceTree = BUILT_PRODUCTS_DIR; }; 90 | 5FB8AC4B24ACF107003B162E /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 91 | 5FB8D7C8237728B300373DC2 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 92 | 5FF72A8F235C9B1400EC8413 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 93 | 5FF72A9A235C9C8F00EC8413 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; 94 | /* End PBXFileReference section */ 95 | 96 | /* Begin PBXFrameworksBuildPhase section */ 97 | 5F3064CD2414AE5100573500 /* Frameworks */ = { 98 | isa = PBXFrameworksBuildPhase; 99 | buildActionMask = 2147483647; 100 | files = ( 101 | ); 102 | runOnlyForDeploymentPostprocessing = 0; 103 | }; 104 | 5F6608DB24027896008F7D0A /* Frameworks */ = { 105 | isa = PBXFrameworksBuildPhase; 106 | buildActionMask = 2147483647; 107 | files = ( 108 | ); 109 | runOnlyForDeploymentPostprocessing = 0; 110 | }; 111 | 5FB8AC4624ACF107003B162E /* Frameworks */ = { 112 | isa = PBXFrameworksBuildPhase; 113 | buildActionMask = 2147483647; 114 | files = ( 115 | ); 116 | runOnlyForDeploymentPostprocessing = 0; 117 | }; 118 | 5FB8D7C3237728B300373DC2 /* Frameworks */ = { 119 | isa = PBXFrameworksBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | ); 123 | runOnlyForDeploymentPostprocessing = 0; 124 | }; 125 | 5FF72A8A235C9B1400EC8413 /* Frameworks */ = { 126 | isa = PBXFrameworksBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | 5FF72A95235C9C8F00EC8413 /* Frameworks */ = { 133 | isa = PBXFrameworksBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | /* End PBXFrameworksBuildPhase section */ 140 | 141 | /* Begin PBXGroup section */ 142 | 5F1C4338234F77F90034E743 /* Pointer */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 5F1C4335234F77E50034E743 /* pointer.h */, 146 | 5F1C4336234F77E50034E743 /* pointer.c */, 147 | ); 148 | path = Pointer; 149 | sourceTree = ""; 150 | }; 151 | 5F1C433A234F787A0034E743 /* Struct */ = { 152 | isa = PBXGroup; 153 | children = ( 154 | 5F1C433B234F788B0034E743 /* struct.h */, 155 | 5F1C433C234F788B0034E743 /* struct.c */, 156 | ); 157 | path = Struct; 158 | sourceTree = ""; 159 | }; 160 | 5F3064D12414AE5100573500 /* stack */ = { 161 | isa = PBXGroup; 162 | children = ( 163 | 5F3064D22414AE5100573500 /* main.c */, 164 | ); 165 | path = stack; 166 | sourceTree = ""; 167 | }; 168 | 5F6608DF24027896008F7D0A /* queue */ = { 169 | isa = PBXGroup; 170 | children = ( 171 | 5F6608E024027896008F7D0A /* main.c */, 172 | ); 173 | path = queue; 174 | sourceTree = ""; 175 | }; 176 | 5F7AAC7923536CF600B876DF /* Malloc */ = { 177 | isa = PBXGroup; 178 | children = ( 179 | 5F7AAC7D23536F5400B876DF /* malloc1.h */, 180 | 5F7AAC7E23536F5400B876DF /* malloc1.c */, 181 | ); 182 | path = Malloc; 183 | sourceTree = ""; 184 | }; 185 | 5FB8AC4A24ACF107003B162E /* tree */ = { 186 | isa = PBXGroup; 187 | children = ( 188 | 5FB8AC4B24ACF107003B162E /* main.c */, 189 | ); 190 | path = tree; 191 | sourceTree = ""; 192 | }; 193 | 5FB8D7C7237728B300373DC2 /* Arr */ = { 194 | isa = PBXGroup; 195 | children = ( 196 | 5FB8D7C8237728B300373DC2 /* main.c */, 197 | ); 198 | path = Arr; 199 | sourceTree = ""; 200 | }; 201 | 5FDE68C221244443003C72AC = { 202 | isa = PBXGroup; 203 | children = ( 204 | 5FF72A8E235C9B1400EC8413 /* poin */, 205 | 5FF72A99235C9C8F00EC8413 /* list */, 206 | 5FB8D7C7237728B300373DC2 /* Arr */, 207 | 5F51AAF723E95EC4002E3084 /* poin */, 208 | 5F51AAF823E95EC4002E3084 /* list */, 209 | 5F51AAF923E95EC4002E3084 /* Arr */, 210 | 5F6608DE24027896008F7D0A /* queue */, 211 | 5F6608DF24027896008F7D0A /* queue */, 212 | 5F3064D02414AE5100573500 /* stack */, 213 | 5F3064D12414AE5100573500 /* stack */, 214 | 5FB8AC4924ACF107003B162E /* tree */, 215 | 5FB8AC4A24ACF107003B162E /* tree */, 216 | ); 217 | sourceTree = ""; 218 | }; 219 | 5FF72A8E235C9B1400EC8413 /* poin */ = { 220 | isa = PBXGroup; 221 | children = ( 222 | 5F7AAC7923536CF600B876DF /* Malloc */, 223 | 5F1C433A234F787A0034E743 /* Struct */, 224 | 5F1C4338234F77F90034E743 /* Pointer */, 225 | 5FF72A8F235C9B1400EC8413 /* main.c */, 226 | ); 227 | path = poin; 228 | sourceTree = ""; 229 | }; 230 | 5FF72A99235C9C8F00EC8413 /* list */ = { 231 | isa = PBXGroup; 232 | children = ( 233 | 5FF72A9A235C9C8F00EC8413 /* main.c */, 234 | ); 235 | path = list; 236 | sourceTree = ""; 237 | }; 238 | /* End PBXGroup section */ 239 | 240 | /* Begin PBXNativeTarget section */ 241 | 5F3064CF2414AE5100573500 /* stack */ = { 242 | isa = PBXNativeTarget; 243 | buildConfigurationList = 5F3064D62414AE5100573500 /* Build configuration list for PBXNativeTarget "stack" */; 244 | buildPhases = ( 245 | 5F3064CC2414AE5100573500 /* Sources */, 246 | 5F3064CD2414AE5100573500 /* Frameworks */, 247 | 5F3064CE2414AE5100573500 /* CopyFiles */, 248 | ); 249 | buildRules = ( 250 | ); 251 | dependencies = ( 252 | ); 253 | name = stack; 254 | productName = stack; 255 | productReference = 5F3064D02414AE5100573500 /* stack */; 256 | productType = "com.apple.product-type.tool"; 257 | }; 258 | 5F6608DD24027896008F7D0A /* queue */ = { 259 | isa = PBXNativeTarget; 260 | buildConfigurationList = 5F6608E424027896008F7D0A /* Build configuration list for PBXNativeTarget "queue" */; 261 | buildPhases = ( 262 | 5F6608DA24027896008F7D0A /* Sources */, 263 | 5F6608DB24027896008F7D0A /* Frameworks */, 264 | 5F6608DC24027896008F7D0A /* CopyFiles */, 265 | ); 266 | buildRules = ( 267 | ); 268 | dependencies = ( 269 | ); 270 | name = queue; 271 | productName = queue; 272 | productReference = 5F6608DE24027896008F7D0A /* queue */; 273 | productType = "com.apple.product-type.tool"; 274 | }; 275 | 5FB8AC4824ACF107003B162E /* tree */ = { 276 | isa = PBXNativeTarget; 277 | buildConfigurationList = 5FB8AC4F24ACF107003B162E /* Build configuration list for PBXNativeTarget "tree" */; 278 | buildPhases = ( 279 | 5FB8AC4524ACF107003B162E /* Sources */, 280 | 5FB8AC4624ACF107003B162E /* Frameworks */, 281 | 5FB8AC4724ACF107003B162E /* CopyFiles */, 282 | ); 283 | buildRules = ( 284 | ); 285 | dependencies = ( 286 | ); 287 | name = tree; 288 | productName = tree; 289 | productReference = 5FB8AC4924ACF107003B162E /* tree */; 290 | productType = "com.apple.product-type.tool"; 291 | }; 292 | 5FB8D7C5237728B300373DC2 /* Arr */ = { 293 | isa = PBXNativeTarget; 294 | buildConfigurationList = 5FB8D7CC237728B300373DC2 /* Build configuration list for PBXNativeTarget "Arr" */; 295 | buildPhases = ( 296 | 5FB8D7C2237728B300373DC2 /* Sources */, 297 | 5FB8D7C3237728B300373DC2 /* Frameworks */, 298 | 5FB8D7C4237728B300373DC2 /* CopyFiles */, 299 | ); 300 | buildRules = ( 301 | ); 302 | dependencies = ( 303 | ); 304 | name = Arr; 305 | productName = Arr; 306 | productReference = 5F51AAF923E95EC4002E3084 /* Arr */; 307 | productType = "com.apple.product-type.tool"; 308 | }; 309 | 5FF72A8C235C9B1400EC8413 /* poin */ = { 310 | isa = PBXNativeTarget; 311 | buildConfigurationList = 5FF72A91235C9B1400EC8413 /* Build configuration list for PBXNativeTarget "poin" */; 312 | buildPhases = ( 313 | 5FF72A89235C9B1400EC8413 /* Sources */, 314 | 5FF72A8A235C9B1400EC8413 /* Frameworks */, 315 | 5FF72A8B235C9B1400EC8413 /* CopyFiles */, 316 | ); 317 | buildRules = ( 318 | ); 319 | dependencies = ( 320 | ); 321 | name = poin; 322 | productName = poin; 323 | productReference = 5F51AAF723E95EC4002E3084 /* poin */; 324 | productType = "com.apple.product-type.tool"; 325 | }; 326 | 5FF72A97235C9C8F00EC8413 /* list */ = { 327 | isa = PBXNativeTarget; 328 | buildConfigurationList = 5FF72A9C235C9C8F00EC8413 /* Build configuration list for PBXNativeTarget "list" */; 329 | buildPhases = ( 330 | 5FF72A94235C9C8F00EC8413 /* Sources */, 331 | 5FF72A95235C9C8F00EC8413 /* Frameworks */, 332 | 5FF72A96235C9C8F00EC8413 /* CopyFiles */, 333 | ); 334 | buildRules = ( 335 | ); 336 | dependencies = ( 337 | ); 338 | name = list; 339 | productName = list; 340 | productReference = 5F51AAF823E95EC4002E3084 /* list */; 341 | productType = "com.apple.product-type.tool"; 342 | }; 343 | /* End PBXNativeTarget section */ 344 | 345 | /* Begin PBXProject section */ 346 | 5FDE68C321244443003C72AC /* Project object */ = { 347 | isa = PBXProject; 348 | attributes = { 349 | LastUpgradeCheck = 0940; 350 | ORGANIZATIONNAME = HerryLo; 351 | TargetAttributes = { 352 | 5F3064CF2414AE5100573500 = { 353 | CreatedOnToolsVersion = 10.1; 354 | }; 355 | 5F6608DD24027896008F7D0A = { 356 | CreatedOnToolsVersion = 10.1; 357 | }; 358 | 5FB8AC4824ACF107003B162E = { 359 | CreatedOnToolsVersion = 11.5; 360 | }; 361 | 5FB8D7C5237728B300373DC2 = { 362 | CreatedOnToolsVersion = 10.1; 363 | }; 364 | 5FF72A8C235C9B1400EC8413 = { 365 | CreatedOnToolsVersion = 10.1; 366 | }; 367 | 5FF72A97235C9C8F00EC8413 = { 368 | CreatedOnToolsVersion = 10.1; 369 | }; 370 | }; 371 | }; 372 | buildConfigurationList = 5FDE68C621244443003C72AC /* Build configuration list for PBXProject "CC" */; 373 | compatibilityVersion = "Xcode 9.3"; 374 | developmentRegion = en; 375 | hasScannedForEncodings = 0; 376 | knownRegions = ( 377 | en, 378 | ); 379 | mainGroup = 5FDE68C221244443003C72AC; 380 | productRefGroup = 5FDE68C221244443003C72AC; 381 | projectDirPath = ""; 382 | projectRoot = ""; 383 | targets = ( 384 | 5FF72A8C235C9B1400EC8413 /* poin */, 385 | 5FF72A97235C9C8F00EC8413 /* list */, 386 | 5FB8D7C5237728B300373DC2 /* Arr */, 387 | 5F6608DD24027896008F7D0A /* queue */, 388 | 5F3064CF2414AE5100573500 /* stack */, 389 | 5FB8AC4824ACF107003B162E /* tree */, 390 | ); 391 | }; 392 | /* End PBXProject section */ 393 | 394 | /* Begin PBXSourcesBuildPhase section */ 395 | 5F3064CC2414AE5100573500 /* Sources */ = { 396 | isa = PBXSourcesBuildPhase; 397 | buildActionMask = 2147483647; 398 | files = ( 399 | 5F3064D32414AE5100573500 /* main.c in Sources */, 400 | ); 401 | runOnlyForDeploymentPostprocessing = 0; 402 | }; 403 | 5F6608DA24027896008F7D0A /* Sources */ = { 404 | isa = PBXSourcesBuildPhase; 405 | buildActionMask = 2147483647; 406 | files = ( 407 | 5F6608E124027896008F7D0A /* main.c in Sources */, 408 | ); 409 | runOnlyForDeploymentPostprocessing = 0; 410 | }; 411 | 5FB8AC4524ACF107003B162E /* Sources */ = { 412 | isa = PBXSourcesBuildPhase; 413 | buildActionMask = 2147483647; 414 | files = ( 415 | 5FB8AC4C24ACF107003B162E /* main.c in Sources */, 416 | ); 417 | runOnlyForDeploymentPostprocessing = 0; 418 | }; 419 | 5FB8D7C2237728B300373DC2 /* Sources */ = { 420 | isa = PBXSourcesBuildPhase; 421 | buildActionMask = 2147483647; 422 | files = ( 423 | 5FB8D7C9237728B300373DC2 /* main.c in Sources */, 424 | ); 425 | runOnlyForDeploymentPostprocessing = 0; 426 | }; 427 | 5FF72A89235C9B1400EC8413 /* Sources */ = { 428 | isa = PBXSourcesBuildPhase; 429 | buildActionMask = 2147483647; 430 | files = ( 431 | 5FF72A90235C9B1400EC8413 /* main.c in Sources */, 432 | ); 433 | runOnlyForDeploymentPostprocessing = 0; 434 | }; 435 | 5FF72A94235C9C8F00EC8413 /* Sources */ = { 436 | isa = PBXSourcesBuildPhase; 437 | buildActionMask = 2147483647; 438 | files = ( 439 | 5FF72A9B235C9C8F00EC8413 /* main.c in Sources */, 440 | ); 441 | runOnlyForDeploymentPostprocessing = 0; 442 | }; 443 | /* End PBXSourcesBuildPhase section */ 444 | 445 | /* Begin XCBuildConfiguration section */ 446 | 5F3064D42414AE5100573500 /* Debug */ = { 447 | isa = XCBuildConfiguration; 448 | buildSettings = { 449 | CODE_SIGN_STYLE = Automatic; 450 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 451 | MTL_FAST_MATH = YES; 452 | PRODUCT_NAME = "$(TARGET_NAME)"; 453 | }; 454 | name = Debug; 455 | }; 456 | 5F3064D52414AE5100573500 /* Release */ = { 457 | isa = XCBuildConfiguration; 458 | buildSettings = { 459 | CODE_SIGN_STYLE = Automatic; 460 | MTL_FAST_MATH = YES; 461 | PRODUCT_NAME = "$(TARGET_NAME)"; 462 | }; 463 | name = Release; 464 | }; 465 | 5F6608E224027896008F7D0A /* Debug */ = { 466 | isa = XCBuildConfiguration; 467 | buildSettings = { 468 | CODE_SIGN_STYLE = Automatic; 469 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 470 | MTL_FAST_MATH = YES; 471 | PRODUCT_NAME = "$(TARGET_NAME)"; 472 | }; 473 | name = Debug; 474 | }; 475 | 5F6608E324027896008F7D0A /* Release */ = { 476 | isa = XCBuildConfiguration; 477 | buildSettings = { 478 | CODE_SIGN_STYLE = Automatic; 479 | MTL_FAST_MATH = YES; 480 | PRODUCT_NAME = "$(TARGET_NAME)"; 481 | }; 482 | name = Release; 483 | }; 484 | 5FB8AC4D24ACF107003B162E /* Debug */ = { 485 | isa = XCBuildConfiguration; 486 | buildSettings = { 487 | CODE_SIGN_STYLE = Automatic; 488 | MACOSX_DEPLOYMENT_TARGET = 10.15; 489 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 490 | MTL_FAST_MATH = YES; 491 | PRODUCT_NAME = "$(TARGET_NAME)"; 492 | }; 493 | name = Debug; 494 | }; 495 | 5FB8AC4E24ACF107003B162E /* Release */ = { 496 | isa = XCBuildConfiguration; 497 | buildSettings = { 498 | CODE_SIGN_STYLE = Automatic; 499 | MACOSX_DEPLOYMENT_TARGET = 10.15; 500 | MTL_FAST_MATH = YES; 501 | PRODUCT_NAME = "$(TARGET_NAME)"; 502 | }; 503 | name = Release; 504 | }; 505 | 5FB8D7CA237728B300373DC2 /* Debug */ = { 506 | isa = XCBuildConfiguration; 507 | buildSettings = { 508 | CODE_SIGN_STYLE = Automatic; 509 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 510 | MTL_FAST_MATH = YES; 511 | PRODUCT_NAME = "$(TARGET_NAME)"; 512 | }; 513 | name = Debug; 514 | }; 515 | 5FB8D7CB237728B300373DC2 /* Release */ = { 516 | isa = XCBuildConfiguration; 517 | buildSettings = { 518 | CODE_SIGN_STYLE = Automatic; 519 | MTL_FAST_MATH = YES; 520 | PRODUCT_NAME = "$(TARGET_NAME)"; 521 | }; 522 | name = Release; 523 | }; 524 | 5FDE68D021244443003C72AC /* Debug */ = { 525 | isa = XCBuildConfiguration; 526 | buildSettings = { 527 | ALWAYS_SEARCH_USER_PATHS = NO; 528 | CLANG_ANALYZER_NONNULL = YES; 529 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 530 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 531 | CLANG_CXX_LIBRARY = "libc++"; 532 | CLANG_ENABLE_MODULES = YES; 533 | CLANG_ENABLE_OBJC_ARC = YES; 534 | CLANG_ENABLE_OBJC_WEAK = YES; 535 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 536 | CLANG_WARN_BOOL_CONVERSION = YES; 537 | CLANG_WARN_COMMA = YES; 538 | CLANG_WARN_CONSTANT_CONVERSION = YES; 539 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 540 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 541 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 542 | CLANG_WARN_EMPTY_BODY = YES; 543 | CLANG_WARN_ENUM_CONVERSION = YES; 544 | CLANG_WARN_INFINITE_RECURSION = YES; 545 | CLANG_WARN_INT_CONVERSION = YES; 546 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 547 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 548 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 549 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 550 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 551 | CLANG_WARN_STRICT_PROTOTYPES = YES; 552 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 553 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 554 | CLANG_WARN_UNREACHABLE_CODE = YES; 555 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 556 | CODE_SIGN_IDENTITY = "-"; 557 | COPY_PHASE_STRIP = NO; 558 | DEBUG_INFORMATION_FORMAT = dwarf; 559 | ENABLE_STRICT_OBJC_MSGSEND = YES; 560 | ENABLE_TESTABILITY = YES; 561 | GCC_C_LANGUAGE_STANDARD = gnu11; 562 | GCC_DYNAMIC_NO_PIC = NO; 563 | GCC_NO_COMMON_BLOCKS = YES; 564 | GCC_OPTIMIZATION_LEVEL = 0; 565 | GCC_PREPROCESSOR_DEFINITIONS = ( 566 | "DEBUG=1", 567 | "$(inherited)", 568 | ); 569 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 570 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 571 | GCC_WARN_UNDECLARED_SELECTOR = YES; 572 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 573 | GCC_WARN_UNUSED_FUNCTION = YES; 574 | GCC_WARN_UNUSED_VARIABLE = YES; 575 | MACOSX_DEPLOYMENT_TARGET = 10.13; 576 | MTL_ENABLE_DEBUG_INFO = YES; 577 | ONLY_ACTIVE_ARCH = YES; 578 | SDKROOT = macosx; 579 | }; 580 | name = Debug; 581 | }; 582 | 5FDE68D121244443003C72AC /* Release */ = { 583 | isa = XCBuildConfiguration; 584 | buildSettings = { 585 | ALWAYS_SEARCH_USER_PATHS = NO; 586 | CLANG_ANALYZER_NONNULL = YES; 587 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 588 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 589 | CLANG_CXX_LIBRARY = "libc++"; 590 | CLANG_ENABLE_MODULES = YES; 591 | CLANG_ENABLE_OBJC_ARC = YES; 592 | CLANG_ENABLE_OBJC_WEAK = YES; 593 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 594 | CLANG_WARN_BOOL_CONVERSION = YES; 595 | CLANG_WARN_COMMA = YES; 596 | CLANG_WARN_CONSTANT_CONVERSION = YES; 597 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 598 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 599 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 600 | CLANG_WARN_EMPTY_BODY = YES; 601 | CLANG_WARN_ENUM_CONVERSION = YES; 602 | CLANG_WARN_INFINITE_RECURSION = YES; 603 | CLANG_WARN_INT_CONVERSION = YES; 604 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 605 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 606 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 607 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 608 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 609 | CLANG_WARN_STRICT_PROTOTYPES = YES; 610 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 611 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 612 | CLANG_WARN_UNREACHABLE_CODE = YES; 613 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 614 | CODE_SIGN_IDENTITY = "-"; 615 | COPY_PHASE_STRIP = NO; 616 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 617 | ENABLE_NS_ASSERTIONS = NO; 618 | ENABLE_STRICT_OBJC_MSGSEND = YES; 619 | GCC_C_LANGUAGE_STANDARD = gnu11; 620 | GCC_NO_COMMON_BLOCKS = YES; 621 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 622 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 623 | GCC_WARN_UNDECLARED_SELECTOR = YES; 624 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 625 | GCC_WARN_UNUSED_FUNCTION = YES; 626 | GCC_WARN_UNUSED_VARIABLE = YES; 627 | MACOSX_DEPLOYMENT_TARGET = 10.13; 628 | MTL_ENABLE_DEBUG_INFO = NO; 629 | SDKROOT = macosx; 630 | }; 631 | name = Release; 632 | }; 633 | 5FF72A92235C9B1400EC8413 /* Debug */ = { 634 | isa = XCBuildConfiguration; 635 | buildSettings = { 636 | CODE_SIGN_STYLE = Automatic; 637 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 638 | MTL_FAST_MATH = YES; 639 | PRODUCT_NAME = "$(TARGET_NAME)"; 640 | }; 641 | name = Debug; 642 | }; 643 | 5FF72A93235C9B1400EC8413 /* Release */ = { 644 | isa = XCBuildConfiguration; 645 | buildSettings = { 646 | CODE_SIGN_STYLE = Automatic; 647 | MTL_FAST_MATH = YES; 648 | PRODUCT_NAME = "$(TARGET_NAME)"; 649 | }; 650 | name = Release; 651 | }; 652 | 5FF72A9D235C9C8F00EC8413 /* Debug */ = { 653 | isa = XCBuildConfiguration; 654 | buildSettings = { 655 | CODE_SIGN_STYLE = Automatic; 656 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 657 | MTL_FAST_MATH = YES; 658 | PRODUCT_NAME = "$(TARGET_NAME)"; 659 | }; 660 | name = Debug; 661 | }; 662 | 5FF72A9E235C9C8F00EC8413 /* Release */ = { 663 | isa = XCBuildConfiguration; 664 | buildSettings = { 665 | CODE_SIGN_STYLE = Automatic; 666 | MTL_FAST_MATH = YES; 667 | PRODUCT_NAME = "$(TARGET_NAME)"; 668 | }; 669 | name = Release; 670 | }; 671 | /* End XCBuildConfiguration section */ 672 | 673 | /* Begin XCConfigurationList section */ 674 | 5F3064D62414AE5100573500 /* Build configuration list for PBXNativeTarget "stack" */ = { 675 | isa = XCConfigurationList; 676 | buildConfigurations = ( 677 | 5F3064D42414AE5100573500 /* Debug */, 678 | 5F3064D52414AE5100573500 /* Release */, 679 | ); 680 | defaultConfigurationIsVisible = 0; 681 | defaultConfigurationName = Release; 682 | }; 683 | 5F6608E424027896008F7D0A /* Build configuration list for PBXNativeTarget "queue" */ = { 684 | isa = XCConfigurationList; 685 | buildConfigurations = ( 686 | 5F6608E224027896008F7D0A /* Debug */, 687 | 5F6608E324027896008F7D0A /* Release */, 688 | ); 689 | defaultConfigurationIsVisible = 0; 690 | defaultConfigurationName = Release; 691 | }; 692 | 5FB8AC4F24ACF107003B162E /* Build configuration list for PBXNativeTarget "tree" */ = { 693 | isa = XCConfigurationList; 694 | buildConfigurations = ( 695 | 5FB8AC4D24ACF107003B162E /* Debug */, 696 | 5FB8AC4E24ACF107003B162E /* Release */, 697 | ); 698 | defaultConfigurationIsVisible = 0; 699 | defaultConfigurationName = Release; 700 | }; 701 | 5FB8D7CC237728B300373DC2 /* Build configuration list for PBXNativeTarget "Arr" */ = { 702 | isa = XCConfigurationList; 703 | buildConfigurations = ( 704 | 5FB8D7CA237728B300373DC2 /* Debug */, 705 | 5FB8D7CB237728B300373DC2 /* Release */, 706 | ); 707 | defaultConfigurationIsVisible = 0; 708 | defaultConfigurationName = Release; 709 | }; 710 | 5FDE68C621244443003C72AC /* Build configuration list for PBXProject "CC" */ = { 711 | isa = XCConfigurationList; 712 | buildConfigurations = ( 713 | 5FDE68D021244443003C72AC /* Debug */, 714 | 5FDE68D121244443003C72AC /* Release */, 715 | ); 716 | defaultConfigurationIsVisible = 0; 717 | defaultConfigurationName = Release; 718 | }; 719 | 5FF72A91235C9B1400EC8413 /* Build configuration list for PBXNativeTarget "poin" */ = { 720 | isa = XCConfigurationList; 721 | buildConfigurations = ( 722 | 5FF72A92235C9B1400EC8413 /* Debug */, 723 | 5FF72A93235C9B1400EC8413 /* Release */, 724 | ); 725 | defaultConfigurationIsVisible = 0; 726 | defaultConfigurationName = Release; 727 | }; 728 | 5FF72A9C235C9C8F00EC8413 /* Build configuration list for PBXNativeTarget "list" */ = { 729 | isa = XCConfigurationList; 730 | buildConfigurations = ( 731 | 5FF72A9D235C9C8F00EC8413 /* Debug */, 732 | 5FF72A9E235C9C8F00EC8413 /* Release */, 733 | ); 734 | defaultConfigurationIsVisible = 0; 735 | defaultConfigurationName = Release; 736 | }; 737 | /* End XCConfigurationList section */ 738 | }; 739 | rootObject = 5FDE68C321244443003C72AC /* Project object */; 740 | } 741 | -------------------------------------------------------------------------------- /CC.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CC.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CC.xcodeproj/project.xcworkspace/xcuserdata/herrylo.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HerryLo/CStruct/31b0cc2176242ff11608feaacd0a0aa860f5dd32/CC.xcodeproj/project.xcworkspace/xcuserdata/herrylo.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /CC.xcodeproj/xcuserdata/herrylo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 22 | 23 | 24 | 26 | 39 | 40 | 41 | 43 | 56 | 57 | 58 | 60 | 73 | 74 | 75 | 77 | 89 | 90 | 91 | 93 | 105 | 106 | 107 | 109 | 121 | 122 | 123 | 125 | 137 | 138 | 139 | 141 | 153 | 154 | 155 | 157 | 169 | 170 | 171 | 173 | 185 | 186 | 187 | 189 | 201 | 202 | 203 | 205 | 217 | 218 | 219 | 221 | 233 | 234 | 235 | 236 | 237 | -------------------------------------------------------------------------------- /CC.xcodeproj/xcuserdata/herrylo.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Arr.xcscheme_^#shared#^_ 8 | 9 | isShown 10 | 11 | orderHint 12 | 0 13 | 14 | CC.xcscheme 15 | 16 | orderHint 17 | 0 18 | 19 | CC.xcscheme_^#shared#^_ 20 | 21 | isShown 22 | 23 | orderHint 24 | 3 25 | 26 | base.xcscheme_^#shared#^_ 27 | 28 | isShown 29 | 30 | orderHint 31 | 4 32 | 33 | list.xcscheme_^#shared#^_ 34 | 35 | isShown 36 | 37 | orderHint 38 | 2 39 | 40 | poin.xcscheme_^#shared#^_ 41 | 42 | isShown 43 | 44 | orderHint 45 | 1 46 | 47 | pointer.xcscheme_^#shared#^_ 48 | 49 | isShown 50 | 51 | orderHint 52 | 6 53 | 54 | queue.xcscheme_^#shared#^_ 55 | 56 | orderHint 57 | 9 58 | 59 | stack.xcscheme_^#shared#^_ 60 | 61 | orderHint 62 | 7 63 | 64 | table.xcscheme_^#shared#^_ 65 | 66 | isShown 67 | 68 | orderHint 69 | 5 70 | 71 | tree.xcscheme_^#shared#^_ 72 | 73 | orderHint 74 | 8 75 | 76 | 77 | SuppressBuildableAutocreation 78 | 79 | 5F48A290235C974D00B5EBD0 80 | 81 | primary 82 | 83 | 84 | 5F48A29B235C97C300B5EBD0 85 | 86 | primary 87 | 88 | 89 | 5FB8D7C5237728B300373DC2 90 | 91 | primary 92 | 93 | 94 | 5FDE68CA21244443003C72AC 95 | 96 | primary 97 | 98 | 99 | 5FF72A81235C9A3E00EC8413 100 | 101 | primary 102 | 103 | 104 | 5FF72A8C235C9B1400EC8413 105 | 106 | primary 107 | 108 | 109 | 5FF72A97235C9C8F00EC8413 110 | 111 | primary 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /img/WechatIMG453.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HerryLo/CStruct/31b0cc2176242ff11608feaacd0a0aa860f5dd32/img/WechatIMG453.png -------------------------------------------------------------------------------- /img/WechatIMG454.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HerryLo/CStruct/31b0cc2176242ff11608feaacd0a0aa860f5dd32/img/WechatIMG454.png -------------------------------------------------------------------------------- /list/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // list 4 | // 5 | // Created by HerryLo on 2019/10/20. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | // 线性结构:离散存储 链表 10 | #include 11 | #include 12 | #include 13 | 14 | // 结构体 15 | typedef struct Node { 16 | int data; // 数据域 17 | struct Node * next; //指针域 18 | }Node, *PNode; 19 | 20 | // 创建非循环单链表 21 | PNode createList(void) { 22 | // 长度 23 | int len; 24 | // 存放用户输入的节点值 25 | int val; 26 | 27 | // 不存放有效数据的头结点 28 | PNode pHead = (PNode)malloc(sizeof(Node)); 29 | if(NULL == pHead) { 30 | printf("分配失败,程序终止!\n"); 31 | exit(-1); 32 | } 33 | 34 | PNode pTail = pHead; 35 | pTail->next = NULL; 36 | 37 | printf("请输入链表的长度: len="); 38 | scanf("%d", &len); 39 | 40 | for (int i = 0; idata = val; 51 | pTail->next = pNew; 52 | pNew->next = NULL; 53 | pTail = pNew; 54 | } 55 | return pHead; 56 | } 57 | 58 | // 遍历 59 | int traverseList(PNode *pHead) { 60 | printf("打印链表的z值:\n"); 61 | PNode next = (*pHead)->next; 62 | while(next != NULL) { 63 | printf("%d \n", next->data); 64 | next = next->next; 65 | } 66 | printf("\n"); 67 | return 0; 68 | } 69 | 70 | // 长度 71 | int lengthList(PNode pHead) { 72 | PNode next = pHead->next; 73 | int i = 0; 74 | while(next != NULL) { 75 | next = next->next; 76 | i++; 77 | } 78 | printf("链表的长度为: %d \n", i); 79 | return i; 80 | } 81 | 82 | // 移除 83 | // pHead 链表头节点 84 | // i 移除的下标,由1开始 85 | bool removeList(PNode pHead, int position, int *pVal) { 86 | PNode p = pHead; 87 | int i = 0; 88 | 89 | // p->next != NULL,移除的前提下,保证要移除的那个只存在; 90 | // 在存在的前提下,p会指向要移除的前一个节点; 91 | while (p->next != NULL && i< position - 1) { 92 | p = p->next; 93 | ++i; 94 | } 95 | 96 | // i > position - 1,防止负数 97 | if(i > position - 1 || p->next == NULL) { 98 | return false; 99 | } 100 | 101 | PNode q = p->next; 102 | *pVal = p->data; 103 | 104 | p->next = p->next->next; 105 | free(q); 106 | q = NULL; 107 | return true; 108 | } 109 | 110 | // 插入 111 | // pHead 链表头节点 112 | // i 插入的下标,由1开始 113 | bool insertList(PNode pHead, int position, int val){ 114 | PNode p = pHead; 115 | int i = 0; 116 | 117 | // p != NULL,插入的前提下,保证要插入位置的前y一个元素存在; 118 | // 在存在的前提下,p会指向要插入的前的节点; 119 | while (p->next != NULL && i< position - 1) { 120 | p = p->next; 121 | ++i; 122 | } 123 | // // i > position - 1,防止负数 124 | if(i > position - 1 || p == NULL) { 125 | return false; 126 | } 127 | 128 | PNode pNew = (PNode)malloc(sizeof(Node)); 129 | if(NULL == pNew) { 130 | printf("分配失败,程序终止!\n"); 131 | exit(-1); 132 | } 133 | pNew->data = val; 134 | pNew->next = p->next; 135 | p->next = pNew; 136 | return true; 137 | } 138 | 139 | 140 | int main() { 141 | // 头结点 142 | PNode pHead = NULL; // 等价于struct Node * pHead = NULL 143 | int value; 144 | 145 | pHead = createList(); 146 | // 移除 147 | removeList(pHead, 8, &value); 148 | // 插入替换 149 | insertList(pHead, 2, 123123); 150 | // 遍历 151 | traverseList(&pHead); 152 | return 0; 153 | } 154 | -------------------------------------------------------------------------------- /poin/Malloc/malloc1.c: -------------------------------------------------------------------------------- 1 | // 2 | // malloc1.c 3 | // CC 4 | // 5 | // Created by HerryLo on 2019/10/13. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | #include "malloc1.h" 10 | #include 11 | 12 | void *malloc(size_t size); 13 | void free(void *ptr); 14 | 15 | void mallocFn() { 16 | // malloc申请动态内存空间 17 | int * p = (int *)malloc(sizeof(4)); // 返回的是第一个字节的地址 18 | 19 | p[0]= 12; 20 | p[1]= 234; 21 | 22 | printf("%d\n", p[0]); 23 | 24 | // free释放内存空间 25 | free(p); // 只是将申请的内存地址标记为释放 26 | // p = NULL; 27 | 28 | printf("%d\n", p[1]); 29 | } 30 | -------------------------------------------------------------------------------- /poin/Malloc/malloc1.h: -------------------------------------------------------------------------------- 1 | // 2 | // malloc1.h 3 | // CC 4 | // 5 | // Created by HerryLo on 2019/10/13. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | #ifndef malloc1_h 10 | #define malloc1_h 11 | 12 | #include 13 | 14 | #endif /* malloc1_h */ 15 | -------------------------------------------------------------------------------- /poin/Pointer/pointer.c: -------------------------------------------------------------------------------- 1 | // 2 | // pointer.c 3 | // CC 4 | // 5 | // Created by HerryLo on 2019/10/10. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | #include "pointer.h" 10 | #include 11 | #include 12 | 13 | // 指针变量 & 示例 14 | // 内存地址是内存单元的编号 15 | // 指针就是内存地址 16 | // 变量指针是存储在内存单元编号的变量 17 | void fn(int * a) { 18 | printf("fn函数中:数组a中第一个值的内存地址: %p\n", a); 19 | a[2] = 12313; 20 | printf("fn函数中:指针a即数组第一个值的内存地址: %d\n", a[1]); 21 | } 22 | 23 | void setValue(int *value) { 24 | printf("打印value地址: %p\n", value); 25 | *value = 787878; 26 | } 27 | 28 | void pointerFn() { 29 | int arr[5] = {1,2,3,4,5}; 30 | int value = 12; 31 | 32 | fn(arr); 33 | printf("pointerFn函数中:数组arr中第一个值的内存地址: %p\n", arr); 34 | printf("pointerFn函数中:数组arr[2]的值:%d\n", arr[2]); 35 | 36 | setValue(&value); 37 | printf("打印value: %d\n", value); 38 | } 39 | -------------------------------------------------------------------------------- /poin/Pointer/pointer.h: -------------------------------------------------------------------------------- 1 | // 2 | // pointer.h 3 | // CC 4 | // 5 | // Created by HerryLo on 2019/10/10. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | #ifndef pointer_h 10 | #define pointer_h 11 | 12 | #include 13 | 14 | #endif /* pointer_h */ 15 | -------------------------------------------------------------------------------- /poin/Struct/struct.c: -------------------------------------------------------------------------------- 1 | // 2 | // struct.c 3 | // CC 4 | // 5 | // Created by HerryLo on 2019/10/10. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | #include "struct.h" 10 | 11 | // 结构体 12 | struct Student { 13 | int id; 14 | char name[20]; 15 | int grade; 16 | }; 17 | 18 | void inputfn(struct Student *c) { 19 | c->id = 2; 20 | 21 | (*c).id = 3; 22 | 23 | printf("%p\n", c); 24 | } 25 | 26 | void structFn() { 27 | struct Student a = {1, "liuheng", 99}; 28 | 29 | printf("%p\n", &a); 30 | 31 | struct Student *b; 32 | 33 | b = &a; 34 | 35 | inputfn(b); 36 | 37 | printf("结构体: %d\n", a.id); 38 | } 39 | -------------------------------------------------------------------------------- /poin/Struct/struct.h: -------------------------------------------------------------------------------- 1 | // 2 | // struct.h 3 | // CC 4 | // 5 | // Created by HerryLo on 2019/10/10. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | #ifndef struct_h 10 | #define struct_h 11 | 12 | #include 13 | 14 | #endif /* struct_h */ 15 | -------------------------------------------------------------------------------- /poin/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // poin 4 | // 5 | // Created by HerryLo on 2019/10/20. 6 | // Copyright © 2019年 HerryLo. All rights reserved. 7 | // 8 | 9 | #include 10 | 11 | //指针 12 | #include "Pointer/pointer.c" 13 | 14 | #include "Malloc/malloc1.c" 15 | 16 | int main(int argc, const char * argv[]) { 17 | // mallocFn(); 18 | pointerFn(); 19 | } 20 | -------------------------------------------------------------------------------- /queue/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // queue 4 | // 5 | // Created by HerryLo on 2020/2/23. 6 | // Copyright © 2020年 HerryLo. All rights reserved. 7 | // 8 | 9 | // 队列之静态循环队列 10 | #include 11 | #include 12 | #include 13 | 14 | int len = 6; 15 | 16 | typedef struct Queue{ 17 | int * PArrry; 18 | int pFront; 19 | int pRear; 20 | }Queue; 21 | 22 | void initQueue(Queue * q) { 23 | q->PArrry = (int *)malloc(sizeof(int)* 6); 24 | q->pFront = 0; 25 | q->pRear = 0; 26 | } 27 | 28 | // 是否满队 29 | bool isFullQueue(Queue * q) { 30 | if((q->pRear + 1)%len == q->pFront) 31 | return true; 32 | return false; 33 | } 34 | 35 | // 是否空队 36 | bool isEmptyQueue(Queue * q) { 37 | if(q->pRear == q->pFront) 38 | return true; 39 | return false; 40 | } 41 | 42 | // 入队 43 | bool inputQueue(Queue * q, int value) { 44 | if(isFullQueue(q)) 45 | return false; 46 | else 47 | q->PArrry[q->pRear] = value; 48 | q->pRear = (q->pRear + 1)%len; 49 | return true; 50 | } 51 | 52 | // 出队 53 | bool outputQueue(Queue * q, int *value) { 54 | if(isEmptyQueue(q)) 55 | return false; 56 | else 57 | *value = q->PArrry[q->pFront]; 58 | q->pFront = (q->pFront + 1)%len; 59 | return true; 60 | } 61 | 62 | // 遍历 63 | void traverseQueue(Queue * q) { 64 | printf("遍历队列中的值\n"); 65 | int front =q->pFront; 66 | while (front != q->pRear) { 67 | printf("%d\n", q->PArrry[front]); 68 | front = (front+1)%len; 69 | } 70 | } 71 | 72 | int main(int argc, const char * argv[]) { 73 | printf("---------循环队列构建---------\n"); 74 | Queue q; 75 | int value; 76 | 77 | initQueue(&q); 78 | 79 | inputQueue(&q, 12); 80 | inputQueue(&q, 12); 81 | inputQueue(&q, 12); 82 | inputQueue(&q, 12); 83 | inputQueue(&q, 12); 84 | inputQueue(&q, 12); 85 | inputQueue(&q, 12); 86 | inputQueue(&q, 12); 87 | traverseQueue(&q); 88 | 89 | outputQueue(&q, &value); 90 | printf("出队值为:%d\n", value); 91 | traverseQueue(&q); 92 | 93 | 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## C语言数据结构 2 | 3 | ![](https://img.shields.io/badge/-C-brightgreen) 4 | ![](https://img.shields.io/badge/-XCode-brightgreen) 5 | 6 | C语言学习数据结构的原因:C语言中存在指针、内存的概念,我们可以手动去操作它。 7 | 8 | 数据结构实际专门是来研究数据存储的问题,而数据的存储包含两个方面:**个体关系 + 个体关系的存储**。 9 | 10 | 环境工具:Mac&Xcode 或者 Window&VSCode 11 | 12 | 以下的内容都是通过学习[郝斌老师数据结构自学视频](https://www.bilibili.com/video/av12907870)后整理,建议感兴趣的同学可以跟着视频学习一波。 13 | 14 | ## 指针Pointer 15 | 16 | **指针就是地址,地址就是指针**。 17 | 18 | 这里的地址就是内存地址。在计算机开发中,我们会使用C/C++、Java、Go、python、NodeJs等高级语言进行软件开发,而在代码中声明的变量,通过编译器编译后,它们就会指向到内存地址中。我们对于变量的操作,实际就是对于计算机内存的操作。 19 | 20 | 内存地址:内存单元的编号,从0到非负整数; 21 | 22 | **指针变量**:**存储内存单元编号的变量**; 23 | 24 | ```C 25 | void main() { 26 | int *p; // 声明指针变量p; 27 | int i = 10; // 声明整型变量i赋值10; 28 | p = &i; // 将i的地址赋值给变量p 29 | printf("%d", *p); // *p == i; 30 | } 31 | ``` 32 | 一个指针变量占几个字节,由变量类型和机型决定。 33 | 34 | ## 结构体Struct 35 | 36 | 结构体用来定义一种数据类型。**struct**定义:用户需要定义的复合数据类型。 37 | 38 | 注意:普通的数据结构无法加减运算,但是可以相互赋值。 39 | 40 | ```c 41 | typedef struct Student { 42 | int id; 43 | int grade; 44 | char name[20]; 45 | }Student; 46 | 47 | // 需要用到指针变量 48 | void Assignment(Student *c) { 49 | c->id = 2; 50 | } 51 | 52 | void main() { 53 | Student a = {1, 1000, "liuheng"}; 54 | Student *b; 55 | b = &a; // &a为变量a的地址,它需要指针变量才可以接收 56 | Assignment(&b); // 传递的是地址 57 | printf("%d\n", a.id); 58 | } 59 | ``` 60 | 结构体变量指针b,存储结构体变量a的地址。 61 | 62 | 注意⚠️:如何判断何时使用指针变量?在函数参数中,一旦你需要传递地址,而对方需要接收时,那么此时必须使用指针变量,当然类型也必须要相同!! 63 | 64 | ## 动态内存 65 | 66 | ```c 67 | void mallocFn() { 68 | // malloc申请动态内存空间 69 | // sizeof设置内存大小,(int *)表示数据类型 70 | int * arr = (int *)malloc(sizeof(5)); // 返回的是第一个字节的地址 71 | 72 | arr[0]= 12; 73 | arr[1]= 234; 74 | printf("%d\n", arr[0]); 75 | 76 | // free释放内存空间 77 | free(arr); // 只是将申请的内存地址标记为释放 78 | arr = NULL; 79 | } 80 | ``` 81 | 注意:通过`malloc`申请得内存空间,一定要记得通过`free`释放。 82 | 83 | ## 数组Array 84 | 85 | 数组是线性结构,在内存中连续存储数据元素的一种数据结构,它是连续存储的。例如🌰:创建一个数组arr,我们可以通过arr[0]、arr[1]、arr[3]来访问数组中的元素。 86 | 87 | 下面是数组的结构体数据类型: 88 | ```c 89 | typedef struct ArrList { 90 | int *p; // 数组中第一个元素的地址 91 | int len; // 数组的长度 92 | int cnt; // 当前有效的长度 93 | }ArrList, *Array 94 | ``` 95 | 96 | 示例如下: 97 | ```c 98 | void main() { 99 | ArrList arr; 100 | 101 | // ....赋值操作省略 102 | 103 | printf("数组长度为:%d\n", arr.len); 104 | printf("数组当前有效长度为:%d\n", arr.cnt); 105 | // arr.p[0] == *(arr.p) 106 | printf("数组当前第一个元素的值:%d\n", arr.p[0]); 107 | } 108 | ``` 109 | **这里的arr.p只是指向数组中第一个元素的内存地址** 110 | 111 | ## 链表List 112 | 113 | 链表是线性结构,在内存中非连续存储数据元素的一种数据结构,它是离散分布的。每个节点通过指针相连,每个一个前驱节点点和后续节点,头节点无前驱节点,尾节点无后续节点。 114 | 115 | 链表的种类:单链表、双链表、循环链表 116 | 117 | 双链表、循环链表是在单链表基础上扩展,下面是单链表结构: 118 | ```c 119 | 头结点:A 首节点:B 尾节点:C 120 | 👇 👇 👇 121 | [data=NULL|next]——>[data|next]——>[data|next]——>[data|next]——>[data|next]——> NULL 122 | ``` 123 | > **头结点**: **第一个有效节点之前的节点,不存放有效数据,加头结点的目的主要是为了方便链表操作**; 124 | 125 | > **首节点**:第一个有效节点; 126 | 127 | > **尾节点**:最后一个有效节点; 128 | 129 | > **头指针**:指向头结点的指针变量; 130 | 131 | > **尾指针**:指向尾结点的指针变量; 132 | 133 | **确定一个链表只需要一个参数:头指针**;链表中单个节点的数据类型: 134 | 135 | ```c 136 | struct Node { 137 | value; // 数据域 138 | next; // 指针域 139 | } 140 | ``` 141 | 142 | 示例如下: 143 | ```c 144 | void main() { 145 | Node * pHead = NULL; //头结点 146 | 147 | // ....赋值操作省略 148 | 149 | // 遍历链表中的值 150 | Node * p = pHead->next; // 首节点 151 | while(p != NULL) { 152 | // 打印节点的值 153 | printf("%d \n", p->data); 154 | p = p->next; 155 | } 156 | 157 | } 158 | ``` 159 | 160 | ## 栈Stack 161 | 162 | **栈是线性结构的具体应用**,类似于箱子📦📦,是一种可以实现“**先进后出**”的存储结构; 163 | 164 | 栈分为静态栈和动态栈,静态栈通常由数组构成,动态栈通常由链表构成(都**只有一个出入口**); 165 | 166 | 以动态栈为🌰🌰,**确认一个栈的节点,只需要两个参数,顶部节点和尾部节点**。 167 | 168 | ```c 169 | struct Stack { 170 | Node Top; 171 | Node Bottom; 172 | } 173 | ``` 174 | 可以想象为了一个放书的箱子📦,想法放入的📖会被后放入的压在下面,而后放入的就会在上面,后放入的必须先拿出,先放入的才可以拿出。 175 | 176 | 应用:函数调用、中断、表达式求值、内存分配、缓存、迷宫等; 177 | 178 | ## 队列Queue 179 | 180 | **队列是线性结构的具体应用**,类似于排队,是一种“**先进先出**”的存储结构。 181 | 182 | 队列分为链式队列和静态队列,前者使用链表实现,后者是数组实现(都是**一头出,一头入**); 183 | 184 | 下面是以静态队列为例子讲解。对于静态队列,它由数组构成,存储空间是一定的,而为了**避免出现空间浪费的问题**,它就必须是一个循环队列(静态队列必须是循环队列);**一个循环队列只需要两个参数:front(头)、rear(尾)**; 185 | 186 | 不同场合front和rear不同的含义: 187 | 188 | > **队列初始化**:front 和 rear 值都是0; 189 | 190 | > **队列非空**:front代表队列的第一个元素;rear代表得失队列最后一个有效元素的下一个元素; 191 | 192 | > **队列为空**:front和rear值相等,但不一定是0; 193 | 194 | **队列算法核心:** 195 | 196 | 入队算法:**rear = (rear+1)%数组长度;** 197 | 198 | 出队算法:**front = (front+1)%数组长度;** 199 | 200 | 可以想象一个水池,一头注水,一头出水,先放入水会先出,后放入的后出。 201 | 202 | ## 递归 203 | 204 | 递归就是一个函数直接或间接调用它自身。 205 | 206 | 递归需要满足三个条件: 207 | * 1. **递归必须得有一个明确的中止条件;** 208 | * 2. **该函数所处理的数据规模必须是递减的;** 209 | * 3. **这个转化是可解的;** 210 | 211 | 循环和递归的比较: 212 | 213 | 递归:易于理解;速度慢;存储空间大; 214 | 215 | 循环:不易于理解;速度快;存储空间小; 216 | 217 | 参考:阶乘、汉诺塔、斐波拉切数列 218 | 219 | ## Tree 树 220 | 221 | 树的专业定义: 222 | 223 | 1. 有且只有一个根节点; 224 | 2. 有若干个互不相交的子树,这些子树本身也是一棵树的通俗定义; 225 | 226 | 树的通俗定义: 227 | 228 | 1. 树由节点和边组成; 229 | 2. 每个节点只有一个父节点,但可以有多个子节点; 230 | 3. 但有一个节点例外,该节点没有父节点,此节点称为根节点; 231 | 232 | 树的分类: 233 | 234 | - 一般树:任意一个节点的子节点的个数不受限制; 235 | - **二叉树:任意一个节点的子节点个数最多两个,且子节点的位置不可更改**; 236 | - 森林:n个互不相交的树的集合; 237 | 238 | ### 二叉树 239 | 240 | 二叉树分类: 241 | 242 | 一般二叉树:任意一个节点的子节点个数最多两个 243 | 244 | **满二叉树**:在不增加树的层数的前提下,无法再多添加一个节点的二叉树就是满二叉树; 245 | 246 | **完全二叉树**:如果只是删除满二叉树最右边的连续若干节点,这样形成的二叉树就是完全二叉树; 247 | 248 | ![](./img/WechatIMG453.png) 249 | 250 | **一般树转换为二叉树**:把一个普通的树转换为二叉树,它一定没有右子节点。转换方法——左指针域指向它的第一个孩子,右指针指向它的兄弟,只要能满足此条件,就可以把普通二叉树转换为二叉树。 251 | 252 | ![](./img/WechatIMG454.png) 253 | 254 | 代码可供参考:[二叉树创建&先序、中序、后序源码链接](https://github.com/HerryLo/CStruct/blob/master/tree/main.c) 255 | -------------------------------------------------------------------------------- /stack/main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HerryLo/CStruct/31b0cc2176242ff11608feaacd0a0aa860f5dd32/stack/main.c -------------------------------------------------------------------------------- /tree/main.c: -------------------------------------------------------------------------------- 1 | // 2 | // main.c 3 | // tree 4 | // 5 | // Created by HerryLo on 2020/7/2. 6 | // Copyright © 2020 HerryLo. All rights reserved. 7 | // 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | typedef char ElemType; 15 | 16 | typedef struct BiTNode { 17 | ElemType data; 18 | struct BiTNode * pLchild; 19 | struct BiTNode * pRchild; 20 | }BiTNode, *BiTree; 21 | 22 | void createTree(BiTree *T); 23 | void preOrderTree(BiTree T); 24 | 25 | int main(int argc, const char * argv[]) { 26 | BiTree bt; //等同于 struct BiTNode * bt 27 | // &bt是一个地址 28 | createTree(&bt); 29 | 30 | preOrderTree(bt); 31 | return 0; 32 | } 33 | 34 | // 创建一个二叉树 35 | // 参数 struct BiTNode * * T 36 | // 参数拆为两部分看,首先 struct BiTNode * 表示的是参数的类型 37 | // *T表示的是一个存储内存地址的指针变量 38 | // 形参 T存储内存地址,*T才是实际传入的值 39 | void createTree(BiTree *T){ 40 | ElemType ch; 41 | printf("输入值:"); 42 | scanf("\n %c", &ch); 43 | if(ch == '#') { 44 | *T = NULL; 45 | }else { 46 | *T = (BiTree)malloc(sizeof(BiTNode)); 47 | if(!*T) { 48 | printf("创建失败!!\n"); 49 | exit(-1); 50 | } 51 | (*T)->data = ch; 52 | createTree(&(*T)->pLchild); 53 | createTree(&(*T)->pRchild); 54 | }; 55 | }; 56 | 57 | // 递归——->先序遍历 58 | // 先访问根节点,再访问左子节点,最后访问右子节点 59 | void preOrderTree(BiTree T){ 60 | if(T == NULL) { 61 | return; 62 | } 63 | printf("%c \n", T->data); 64 | preOrderTree(T->pLchild); 65 | preOrderTree(T->pRchild); 66 | }; 67 | --------------------------------------------------------------------------------