
数据结构
江河(Krisen)
关关难过关关过,长路漫漫且灿灿,山山漫漫结成关,人人草草尽走散
展开
-
哈希表
输入0 向哈希表插入元素 输入1 查找内容是否在哈希表#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct Node{ char *str; struct Node *next;}Node;typedef struct HashTable{ Node **data; int size;}HashTable;Node *init_nod原创 2020-12-10 16:21:01 · 148 阅读 · 0 评论 -
二分法
#include <stdio.h>#define P(func){\ printf("%s = %d\n",#func,func);\}// 1 3 5 7 9 10 int binary_search1(int *num, int n,int x){ int head=0,tail=n-1,mid; while(head<=tail){ mid=(head+tail)>>1; if(num[mid]==x)原创 2020-12-10 13:53:22 · 114 阅读 · 0 评论 -
选择排序 快速排序
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>#define swap(a,b){\ __typeof(a) __temp =a;\ a=b;b=__temp;\}#define TEST(arr, n, func,args...){\ int *num=(int *)malloc(sizeof(int)*n);\原创 2020-12-07 17:39:58 · 325 阅读 · 0 评论 -
插入、冒泡、归并排序
#include <stdio.h>#include <stdlib.h>#include <time.h>#include <string.h>#define swap(a,b){\ a^=b; b^=a;a^=b;\}#define TEST(arr, n, func,args...){\ //args代表后面所有的参数 int *num=(int *)malloc(sizeof(int)*n);\原创 2020-12-07 10:01:04 · 136 阅读 · 0 评论 -
广义表转二叉树
#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct Node{ char data; struct Node *lchild,*rchild;}Node;typedef struct Tree{ Node *root; int n;}Tree;typedef struct Stack{ Node **data;原创 2020-12-05 18:37:13 · 229 阅读 · 0 评论 -
树和二叉树
树-深度、高度和度树的深度(高度)为52.节点4的深度为2,高度为43.节点2的度为1,节点1的度为3 度就是有几个子孩子4.节点数量等于边数+1二叉查找树的三种遍历#include <stdio.h>#include <stdlib.h>#include <time.h>typedef struct Node{ int data; struct Node *lchild ,*rchild;}Node;typedef原创 2020-12-03 20:25:33 · 141 阅读 · 0 评论 -
栈
栈栈,可以处理具有完全包含关系的问题#include <stdio.h>#include <stdlib.h>#include <time.h>typedef struct stack{ int *data; int size,top;}Stack;Stack *init(int n){ Stack *p=(Stack*)malloc(sizeof(Stack)); p->data=(int *)malloc(siz原创 2020-12-03 10:04:56 · 129 阅读 · 0 评论 -
队列的插入和删除
代码如下:#include <stdio.h>#include <stdlib.h>#include <time.h>typedef struct Queue{ int *data; int head,tail,length,cnt;} Queue;Queue *init(int n){ Queue *q =(Queue *)malloc(sizeof(Queue)); q->data = (int *)malloc(原创 2020-12-01 20:57:39 · 2058 阅读 · 0 评论 -
链表的增删改查
#include<stdio.h>#include<stdlib.h>#include <time.h>typedef struct ListNode{ int data; struct ListNode *next;}ListNode;typedef struct List{ ListNode head; int length;}List;ListNode *getNewNode(int);List *getLinkL原创 2020-12-01 14:22:34 · 285 阅读 · 0 评论 -
顺序表
顺序表的插入和删除代码如下:#include<stdio.h>#include<stdlib.h>#include <time.h>typedef struct Vector{ int *data; int size,length;}Vec;Vec *init(int n) //函数指针{ Vec *v=(Vec *)malloc(sizeof(Vec)); v->data=(int*)malloc(s原创 2020-11-30 17:56:42 · 155 阅读 · 0 评论