21:31:04 2019-08-17
今天开始的时间有点晚
00:09:22 2019-08-18
又重新开始学 希望这次能够入门 每天开始学习数据结构的时间有点晚了 要调整一下
单链表
List.h
1 #ifndef _LIST_H 2 #define _LIST_H 3 #define len sizeof(Node) 4 struct Node; 5 typedef struct Node* PtrToNode; 6 typedef PtrToNode List; 7 typedef PtrToNode Position; 8 List MakeEmety(List L); 9 int IsEmpty(List L); 10 int IsLast(Position P, List L); 11 Position Find(int Element, List L); 12 void Delete(int Element, List L); 13 Position FindPrevious(int Element, List L); 14 void Insert(int Element, List L, Position P); 15 void DeleteList(List L); 16 Position Header(List L); 17 Position First(List L); 18 19 #endif // !_LIST_H
List.c
1 #include<malloc.h> 2 #include "List.h" 3 struct Node 4 { 5 int Element; 6 Position Next; 7 }; 8 List MakeEmety(List L) 9 { 10 List head = (List)malloc(len); 11 head->Next = NULL; 12 return head; 13 } 14 15 int IsEmpty(List L) 16 { 17 return L->Next == NULL; 18 } 19 20 int IsLast(Position P, List L) 21 { 22 return P->Next == NULL; 23 } 24 25 Position Find(int Element, List L) 26 { 27 Position P = L->Next; 28 while (P!=NULL) 29 { 30 if (P->Element == Element) 31 return P; 32 else 33 P = P->Next; 34 } 35 return NULL; 36 } 37 38 void Delete(int Element, List L) 39 { 40 Position P1, P2; 41 P1=P2= FindPrevious(Element,L); 42 P1->Next = P1->Next->Next; 43 free(P2); 44 } 45 46 Position FindPrevious(int Element, List L) 47 { 48 Position P = L; 49 while (P ->Next!= NULL) 50 { 51 if (P->Next->Element == Element) 52 return P; 53 else 54 P = P->Next; 55 } 56 return NULL; 57 } 58 59 void Insert(int Element, List L, Position P) 60 { 61 Position P1 = (Position)malloc(len); 62 P->Element = Element; 63 Position PreP = FindPrevious(P->Element,L); 64 P1->Next = P; 65 PreP->Next = P1; 66 } 67 68 void DeleteList(List L) 69 { 70 Position P1, P2; 71 P1 = P2 = L; 72 while (P2!= NULL) 73 { 74 P2 = P1->Next; 75 free(P1); 76 P1 = P2; 77 } 78 } 79 80 Position Header(List L) 81 { 82 return L; 83 } 84 85 Position First(List L) 86 { 87 return L; 88 }
原文:https://www.cnblogs.com/57one/p/11370756.html