数据结构 初始数据结构 基础理论
图片地址
https://cdn.jsdelivr.net/gh/codexiaobo/image@main/数据结构/考研数据结构-第一章.7lhc0556ays0.jpg
PDF文档地址
https://urlify.cn/uyEZnq
线性表 和 链表 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 # include <stdio.h> # define MAXSIZE 20 typedef int ElemType;typedef struct { ElemType data[MAXSIZE]; int length; }sqList; int getElem (sqList L, int i, ElemType* e) { if (L.length == 0 || i < 1 || i > L.length) { return 0 ; } *e = L.data[i - 1 ]; return 1 ; } int listInsert (sqList L, int i, ElemType e) { if (L.length == MAXSIZE) { return 0 ; } if (i < 1 || i > L.length) { return 0 ; } if (i <= L.length) { for (int k = L.length; k >= i - 1 ; k--) { L.data[k + 1 ] = L.data[k]; } } L.data[i - 1 ] = e; L.length++; return 1 ; } int main () { sqList sqList; printf ("%d" ,listInsert(sqList, 3 , 2 )); return 0 ; }
单链表 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 # include <stdio.h> # include <stdlib.h> #include <stdbool.h> typedef int ElemType;typedef struct LNode { ElemType data; struct LNode *next ; }LNode,*LinkList; bool ListInsert1 (LinkList L, int i, ElemType e) { if (i < 1 ) { return false ; } LNode* p; int j = 0 ; p = L; while (p->next != NULL && j < i - 1 ){ p = p->next; j++; } if (p == NULL ) { return false ; } LNode* s = (LNode *)malloc (sizeof (LNode)); s->data = e; s->next = p->next; p->next = s; return true ; } bool ListInsert2 (LinkList L, int i, ElemType e) { if (i < 1 ) { return false ; } if (i == 1 ) { LNode* s = (LNode *)malloc (sizeof (LNode)); s->data = e; s->next = NULL ; L = s; return true ; } LNode* p; int j = 1 ; p = L; while (p->next != NULL && j < i - 1 ) { p = p->next; j++; } if (p == NULL ) { return false ; } LNode* s = (LNode*)malloc (sizeof (LNode)); s->data = e; s->next = p->next; p->next = s; return true ; } bool ListlaterInsert (LNode* p, ElemType e) { if (p == NULL ) { return false ; } LNode* s = (LNode*)malloc (sizeof (LNode)); if (s == NULL ) { return false ; } s->data = e; s->next = p->next; p->next = s; return true ; } bool ListBeforeInsert (LNode* p, ElemType e) { LNode* s = (LNode*)malloc (sizeof (LNode)); if (s == NULL || p == NULL ) { return false ; } s->next = p->next; p->next = s; ElemType temp = p->data; p->data = s->data; s->data = temp; return true ; } bool ListDelete (LinkList L, int i, ElemType e) { if (i < 1 ) { return false ; } LNode* p; int j = 0 ; p = L; while (p == NULL && j < i - 1 ) { p = p->next; j++; } if (p == NULL || p->next == NULL ) { return false ; } LNode* q = p->next; e = q->data; p->next = q->next; free (q); return true ; } bool LinkListDelete (LNode* p) { if (p == NULL ) { return false ; } LNode* q = p->next; p->data = q->data; p->next = q->next; free (q); return true ; } LNode* GetElem (LinkList L, int i) { if (i < 0 ) { return NULL ; } LNode* p; int j = 0 ; p = L; while (p != NULL && j < i) { p = p->next; j++; } return p; } LNode* LocateElem (LinkList L, ElemType e) { LNode* p = L->next; while (p != NULL && p->data != e) { p = p->next; } return p; } int Length (LinkList L) { int len = 0 ; LNode* p = L; while (p->next != NULL ) { p = p->next; len++; } return len; } bool initList (LinkList L) { L = (LNode*)malloc (sizeof (LNode)); if (L == NULL ) { return false ; } L->next = NULL ; return true ; } LinkList List_TailInsert (LinkList L) { int x; L = (LinkList)malloc (sizeof (LinkList)); LNode* s,* r = L; scanf_s("%d" , &x); while (x != 9999 ) { s = (LNode*)malloc (sizeof (LNode)); s->data = x; r->next = s; r = s; scanf_s("%d" , &x); } r->next = NULL ; return L; } LinkList list_HeadInsert (LinkList L) { LNode* s; int x; L = (LinkList*)malloc (sizeof (LinkList)); scanf_s("%d" , &x); while (x != 9999 ) { s = (LNode *)malloc (sizeof (LNode)); s->data = x; s->next = L->next; L->next = s; scanf_s("%d" , &x); } return L; }
双链表 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 # include <stdio.h> # include <stdlib.h> # include <stdbool.h> typedef int ElemType;typedef struct DNode { ElemType data; struct DNode * prior , * next ; }DNode,*DLinkList; bool initDLinkList (DLinkList L) { L = (DNode*)malloc (sizeof (DNode)); if (L == NULL ) { return false ; } L->prior = NULL ; L->next = NULL ; return false ; } bool Empty (DLinkList L) { if (L->next == NULL ) { return true ; } else { return false ; } } bool InsertNextDNode (DNode* p, DNode* s) { if (p == NULL || s == NULL ) { return false ; } s->next = p->next; if (p->next != NULL ) { p->next->prior = s; } s->prior = p; p->next = s; return true ; } bool DeleteNextDNode (DNode* p) { if (p == NULL ) { return false ; } DNode* q = p->next; if (q == NULL ) { return false ; } p->next = q->next; if (q->next != NULL ) { q->next->prior = p; } free (q); return true ; } void DestoryList (DLinkList L) { while (L->next != NULL ) { DeleteNextDNode(L); } free (L); L = NULL ; } DNode* selectLinkList (DNode *p) { while (p->next != NULL ) { p = p->next; } while (p->prior != NULL ) { p = p->prior; } while (p != NULL ) { p = p->next; } while (p != NULL ) { p = p->prior; } }
循环链表 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 # include <stdio.h> # include <stdlib.h> # include <stdbool.h> typedef int ElemType;typedef struct DNode { ElemType data; DNode* prior; DNode* next; }DNode,* LinkList; bool initList (LinkList L) { L = (DNode*)malloc (sizeof (DNode)); if (L == NULL ) { return false ; } L->next = L; L->prior = L; return true ; }
图片地址
https://cdn.jsdelivr.net/gh/codexiaobo/image@main/数据结构/考研数据结构-第二章.1oz2o4mj1deo.jpg
PDF文档地址
https://urlify.cn/uyEZnq
栈 和 队列 顺序栈 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 # include <stdio.h> # include <stdlib.h> # include <stdbool.h> #define maxSize 10 typedef int ElemType;typedef struct { ElemType data[maxSize]; int top; }sqStack; bool initStack (sqStack *s) { s->top = -1 ; } bool StackEmpty (sqStack* s) { if (s->top == -1 ) { return true ; } else { return false ; } } bool push (sqStack *s,ElemType x) { if (s->top == maxSize - 1 ) { return false ; } s->top = s->top + 1 ; s->data[s->top] = x; return true ; } bool pop (sqStack* s, ElemType x) { if (s->top == -1 ) { return false ; } x = s->data[s->top]; s->top = s->top - 1 ; return true ; } bool getTop (sqStack* s, ElemType x) { if (s->top == NULL ) { return false ; } x = s->data[s->top]; return true ; } bool kuohao (char str[], int length) { sqStack *s; initStack(s); for (int i = 0 ; i < length; i++) { if (str[i] == '(' || str[i] == '[' || str[i] == '{' ) { push(s,str[i]); } else { if (StackEmpty(s)){ return false ; } int temp; pop(s,temp); if (str[i] == ')' && temp != '(' ) { return false ; } if (str[i] == ']' && temp != '[' ) { return false ; } if (str[i] == '}' && temp != '{' ) { return false ; } } } return StackEmpty(s); }
顺序队列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 # include <stdio.h> # include <stdlib.h> # include <stdbool.h> #define maxSize 10 typedef int ElemType;typedef struct { ElemType data[maxSize]; ElemType front, rear; }SqQueue; bool InitQueue (SqQueue* q) { q->front = q->rear = 0 ; return true ; } bool QueueEmpty (SqQueue* q) { if (q->front == q->rear) { return true ; } else { return false ; } } bool EnQueue (SqQueue* q, int x) { if ((q->rear + 1 ) % maxSize == q->front) { return false ; } q->data[q->rear] = x; q->rear = (q->rear + 1 ) % maxSize; return true ; } bool DeQueue (SqQueue* q,int x) { if (q->front == q->rear) { return false ; } x = q->data[q->front]; q->front = (q->front + 1 ) % maxSize; return true ; }
链式队列 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 # include <stdio.h> # include <stdlib.h> # include <stdbool.h> typedef int ElemType;typedef struct LinkNode { ElemType data; struct LinkNode * next ; }LinkNode; typedef struct { LinkNode * front, * rear; }LinkQueue; void InitQueue (LinkQueue* q) { q->front = q->rear = (LinkNode*)malloc (sizeof (LinkNode)); q->rear = NULL ; } bool EmptyQueue (LinkQueue* q) { if (q->front == q->rear) { return true ; } else { return false ; } } void InitQueue2 (LinkQueue* q) { q->front = NULL ; q->rear = NULL ; } bool EnQueue (LinkQueue* q, int x) { LinkNode* s = (LinkNode *)malloc (sizeof (LinkNode)); s->data = x; s->next = NULL ; q->rear->next = s; q->rear = s; } void EnQueue2 (LinkQueue *q,ElemType x) { LinkNode *s = (LinkNode*)malloc (sizeof (LinkNode)); s->data = x; s->next = NULL ; if (q->front == NULL ) { q->front = s; q->rear = s; } else { q->rear->next = s; q->rear = s; } } bool DeQueue (LinkQueue* q, int x) { if (q->front == q->rear) { return false ; } LinkNode* p = q->front->next; x = p->data; q->front->next = p->next; if (q->rear == p) { q->rear = q->front; } free (q); return true ; } bool DeQueue2 (LinkQueue* q, int x) { LinkNode* p = q->front; x = p->data; q->front = p->next; if (q->rear == p) { q->rear = NULL ; q->front = NULL ; } free (p); return true ; }
图片地址
https://cdn.jsdelivr.net/gh/codexiaobo/image@main/数据结构/考研数据结构-第三章.650lhlnzy9s0.jpg
PDF文档地址
https://urlify.cn/uyEZnq
正确的开始 微小的长进 然后持续 嘿 我是小博 带你一起看我目之所及的世界……