├── Huffman tree ├── Function.cpp ├── data_structure.h └── main.cpp ├── Trie Tree ├── data_structure.h ├── function.cpp └── main.cpp ├── linux下编译的 ├── back │ └── back.c ├── digui │ └── digui.c ├── hannuota │ └── tower.c ├── list │ └── list.c ├── roundqueue │ └── roundqueue.c ├── sort │ └── quicksort.c └── stack │ └── stack.c ├── 二叉排序树 └── BST.CPP ├── 二叉树 ├── 二叉树的递归遍历 │ └── 二叉树遍历的递归实现.cpp └── 二叉树遍历的非递归实现 │ ├── data_structure.h │ ├── stack_mthod.cpp │ ├── traverse_tree.cpp │ └── tree_method.cpp ├── 单链表 ├── 单链表无头结点版 │ ├── check_list.cpp │ ├── delete_data.cpp │ ├── free.cpp │ ├── input.cpp │ ├── insert.cpp │ ├── itm_count.cpp │ ├── link_main.cpp │ ├── show.cpp │ ├── sll_node.h │ └── sort_show.cpp └── 单链表有头结点版 │ └── list.cpp ├── 各种排序 ├── shell排序 │ └── shell排序.cpp ├── 冒泡排序 │ ├── 原始冒泡排序 │ │ └── BubbleSort.cpp │ └── 改进冒泡排序 │ │ └── UpdatedBubbleSort.cpp ├── 基数排序 │ └── BasicSort.cpp ├── 堆排序 │ └── HeapSort.cpp ├── 归并排序 │ ├── 我实现的代码 │ │ └── MergeSort.cpp │ └── 经典实现代码 │ │ └── MergeSort.cpp ├── 快速排序 │ └── QuickSort.cpp ├── 插入排序 │ ├── 折半插入排序 │ │ └── 折半插入排序.cpp │ └── 直接插入排序 │ │ └── 插入排序.cpp ├── 计数排序 │ └── CountSort.cpp └── 选择排序 │ └── Select_Sort.cpp ├── 哈希表 ├── data_structure.h ├── function_hash.cpp └── main.cpp ├── 图的遍历 ├── data_structure.h ├── function_graph.cpp ├── function_queue.cpp └── main.cpp ├── 数组循环移位 ├── 循环右移算法 │ └── Cpp1.cpp └── 循环左移算法 │ └── 数组循环左移.cpp ├── 模式匹配 BF—KMP ├── BF算法 │ └── simple_index.cpp └── KMP算法 │ └── kmp_index.cpp ├── 链式栈 └── Stack.cpp └── 链式队列 └── 链式队列.cpp /Huffman tree/Function.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/Huffman tree/Function.cpp -------------------------------------------------------------------------------- /Huffman tree/data_structure.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/Huffman tree/data_structure.h -------------------------------------------------------------------------------- /Huffman tree/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/Huffman tree/main.cpp -------------------------------------------------------------------------------- /Trie Tree/data_structure.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/Trie Tree/data_structure.h -------------------------------------------------------------------------------- /Trie Tree/function.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/Trie Tree/function.cpp -------------------------------------------------------------------------------- /Trie Tree/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include"data_structure.h" 3 | 4 | int main() 5 | { 6 | char str[10]; 7 | TrieTree pTree = create_TrieTree(); 8 | 9 | printf("Please input all string:\n"); 10 | while(gets(str) && str[0] != '\0') 11 | insert_TrieTree(pTree,str); 12 | 13 | printf("\nplease intput prefix string:\n"); 14 | while(gets(str) && str[0] != '\0') 15 | printf("The num of strings started with %s is %d\n",str,count_TrieTree(pTree,str)); 16 | 17 | destroy_TrieTree(pTree); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /linux下编译的/back/back.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/linux下编译的/back/back.c -------------------------------------------------------------------------------- /linux下编译的/digui/digui.c: -------------------------------------------------------------------------------- 1 | /********************************** 2 | 数据结构与算法分析第八页1.3题源代码 3 | 用递归方法打印出输入的任意整数 4 | **********************************/ 5 | 6 | #include 7 | #include 8 | void printDigit(int); 9 | void printOut(long); 10 | void printPositive(unsigned long); 11 | int main(void) 12 | { 13 | int a; 14 | printf("Input a num(q to exit):"); 15 | while(scanf("%d",&a)==1) 16 | { 17 | printf("Output:"); 18 | printOut(a); 19 | printf("\nInpout another num(q to exit):"); 20 | } 21 | printf("Byebye!\n"); 22 | return 0; 23 | } 24 | 25 | 26 | //该函数用于输出任意整数的值 27 | void printOut(long N) 28 | { 29 | if(N>0) 30 | printPositive(N); 31 | else if(N<0) 32 | { 33 | printf("-"); 34 | printPositive(abs(N)); 35 | } 36 | else 37 | printDigit(N); 38 | } 39 | 40 | 41 | //该函数用于输出正整数的值 42 | void printPositive(unsigned long N) 43 | { 44 | if(N>10||N==10) 45 | printPositive(N/10); 46 | printDigit(N%10); 47 | } 48 | 49 | 50 | //该函数负责输出小于10的非负整数值 51 | void printDigit(int N) 52 | { 53 | printf("%d",N); 54 | } 55 | -------------------------------------------------------------------------------- /linux下编译的/hannuota/tower.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | 汉诺塔的递归实现算法,将A中的圆盘借助B圆盘完全移动到C圆盘上, 3 | 每次只能移动一个圆盘,并且每次移动时大盘不能放在小盘上面 4 | 递归函数的伪算法为如下: 5 | if(n == 1) 6 | 直接将A柱子上的圆盘从A移动到C 7 | else 8 | 先将A柱子上的n-1个圆盘借助C柱子移动到B柱子上 9 | 直接将A柱子上的第n个圆盘移动到C柱子上 10 | 最后将B柱子上的n-1个圆盘借助A柱子移动到C柱子上 11 | 12 | 该递归算法的时间复杂度为O(2的n次方),当有n个圆盘时,需要移动圆盘2的n次方-1次 13 | ****************************************************************************/ 14 | 15 | #include 16 | 17 | void move(int,char,char,char); 18 | 19 | int main() 20 | { 21 | //A、B、C分别代表三个柱子 22 | char ch1 = 'A'; 23 | char ch2 = 'B'; 24 | char ch3 = 'C'; 25 | 26 | //n代表圆盘的个数 27 | int n; 28 | printf("请输入圆盘个数:"); 29 | scanf("%d",&n); 30 | move(n,ch1,ch2,ch3); 31 | 32 | return 0; 33 | } 34 | 35 | /* 36 | 将n个圆盘从x柱子借助y柱子移动到z柱子上 37 | */ 38 | void move(int n,char x,char y,char z) 39 | { 40 | if(n == 1) 41 | printf("圆盘编号%d:从%c移动到%c\n",n,x,z); 42 | else 43 | { 44 | move(n-1,x,z,y); 45 | printf("圆盘编号%d:从%c移动到%c\n",n,x,z); 46 | move(n-1,y,x,z); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /linux下编译的/list/list.c: -------------------------------------------------------------------------------- 1 | /************************************************************************************************************** 2 | 以下为操作链表的算法,该链表为单链表。 3 | 链表以头指针为索引,头指针指向头节点,头节点指向首节点,以此类推,直到尾节点。 4 | 头节点中不存放数据,只存放指向首节点的指针, 5 | 设置头节点的目的是为了方便对链表的操作,如果不设置头节点,而是直接由头指针指向首节点, 6 | 这样在对头指针后的节点进行插入删除操作时就会与其他节点进行该操作时有所不同,便要作为一种特殊情况来分析 7 | **************************************************************************************************************/ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | typedef struct Node 14 | { 15 | int data; 16 | struct Node *pNext; 17 | }NODE,*PNODE; 18 | 19 | PNODE create_list(); 20 | void traverse_list(PNODE); 21 | bool is_empty(PNODE); 22 | int length_list(PNODE); 23 | void sort_list(PNODE); 24 | bool insert_list(PNODE,int,int); 25 | bool delete_list(PNODE,int,int *); 26 | void clear_list(PNODE); 27 | 28 | int main(void) 29 | { 30 | int len; 31 | int data_del; 32 | PNODE pHead = NULL; 33 | 34 | //创建链表并遍历输出 35 | pHead = create_list(); 36 | traverse_list(pHead); 37 | 38 | //求链表长度,并输出 39 | len = length_list(pHead); 40 | if(!is_empty(pHead)) 41 | printf("the length of the list is:%d\n",len); 42 | 43 | //向链表中插入数据,并重新遍历输出 44 | if(insert_list(pHead,3,78)) 45 | printf("insert succeed,"); 46 | else 47 | printf("insert failed,"); 48 | traverse_list(pHead); 49 | 50 | //从链表中删除数据,并重新遍历输出 51 | if(delete_list(pHead,3,&data_del)) 52 | { 53 | printf("delete succeed,the deleted data is:%d\n",data_del); 54 | } 55 | else 56 | printf("delete failed,"); 57 | traverse_list(pHead); 58 | 59 | //对链表排序,重新遍历输出 60 | sort_list(pHead); 61 | printf("After sorted,"); 62 | traverse_list(pHead); 63 | 64 | //清空链表,遍历输出(无数据输出) 65 | clear_list(pHead); 66 | printf("After cleared,"); 67 | traverse_list(pHead); 68 | return 0; 69 | } 70 | 71 | /* 72 | 创建一个链表,并返回头指针 73 | */ 74 | PNODE create_list() 75 | { 76 | int val; 77 | PNODE pHead =(PNODE)malloc(sizeof(NODE)); 78 | PNODE pCurrent = pHead; 79 | pCurrent->pNext = NULL; 80 | if(NULL == pHead) 81 | { 82 | printf("pHead malloc failed!"); 83 | exit(-1); 84 | } 85 | printf("Input first data(q to quit):"); 86 | while(scanf("%d",&val)==1) 87 | { 88 | PNODE pNew = (PNODE)malloc(sizeof(NODE)); 89 | if(NULL == pNew) 90 | { 91 | printf("pNew malloc failed!"); 92 | exit(-1); 93 | } 94 | pNew->data = val; 95 | pCurrent->pNext = pNew; 96 | pNew->pNext = NULL; 97 | pCurrent = pNew; 98 | printf("Input next data(q to quit):"); 99 | } 100 | 101 | return pHead; 102 | } 103 | 104 | /* 105 | 遍历链表 106 | */ 107 | void traverse_list(PNODE pHead) 108 | { 109 | PNODE pCurrent = pHead->pNext; 110 | printf("now dataes in the list are:\n"); 111 | while(pCurrent != NULL) 112 | { 113 | printf("%d ",pCurrent->data); 114 | pCurrent = pCurrent->pNext; 115 | } 116 | printf("\n"); 117 | return ; 118 | } 119 | 120 | /* 121 | 判断链表是否为空 122 | */ 123 | bool is_empty(PNODE pNode) 124 | { 125 | if(NULL == pNode->pNext) 126 | return true; 127 | else 128 | return false; 129 | } 130 | 131 | /* 132 | 求链表长度,即节点总数(不计入头节点) 133 | */ 134 | int length_list(PNODE pNode) 135 | { 136 | int count = 0; 137 | PNODE pCurrent = pNode->pNext; 138 | while(pCurrent != NULL) 139 | { 140 | count++; 141 | pCurrent = pCurrent->pNext; 142 | } 143 | 144 | return count; 145 | } 146 | 147 | /* 148 | 冒泡法对链表排序 149 | */ 150 | void sort_list(PNODE pHead) 151 | { 152 | PNODE p,q; 153 | int temp; 154 | for(p=pHead->pNext;p!=NULL;p=p->pNext) 155 | for(q=p->pNext;q!=NULL;q=q->pNext) 156 | { 157 | if(p->data>q->data) 158 | { 159 | temp = p->data; 160 | p->data = q->data; 161 | q->data = temp; 162 | } 163 | } 164 | 165 | return ; 166 | } 167 | 168 | /* 169 | 在第pos个节点的后面插入一个新的节点,该节点中的数据为val 170 | */ 171 | bool insert_list(PNODE pHead,int pos,int val) 172 | { 173 | int i = 0; 174 | PNODE p = pHead; 175 | 176 | //i为0时,p指向第0个节点(这里指没有实际数据的头节点,不计入链表节点总数), 177 | //i为1时,p指向第1个节点,i为几,p就指向第几个节点 178 | while(p!=NULL && ipNext; 181 | i++; 182 | } 183 | 184 | //当pos的值大于链表长度时,便会出现这种情况 185 | if(i>pos || p==NULL) 186 | return false; 187 | 188 | PNODE pNew = (PNODE)malloc(sizeof(NODE)); 189 | if(NULL == pNew) 190 | { 191 | printf("pNew malloc failed!"); 192 | exit(-1); 193 | } 194 | pNew->data = val; 195 | pNew->pNext = p->pNext; 196 | p->pNext = pNew; 197 | 198 | return true; 199 | } 200 | 201 | /* 202 | 删除第pos个节点,并将删除的数据保存在pData指针所指向的位置 203 | */ 204 | bool delete_list(PNODE pHead,int pos,int *pData) 205 | { 206 | int i = 0; 207 | PNODE p = pHead; 208 | 209 | //p最终指向第pos个节点前面的节点 210 | //如果下面两句分别改为while(p!=NULL && ipos || p==NULL),则p最终指向第pos个节点, 211 | //这样因为得不到第pos个节点前面的那个节点,因此无法将pos前后两个节点连结起来 212 | while(p->pNext!=NULL && ipNext; 215 | i++; 216 | } 217 | 218 | //当pos的值大于链表长度时,便会出现这种情况 219 | if(i>pos-1 || p->pNext==NULL) 220 | return false; 221 | 222 | PNODE q = p->pNext; 223 | *pData = q->data; 224 | p->pNext = p->pNext->pNext; 225 | free(q); 226 | q = NULL; 227 | return true; 228 | } 229 | 230 | /* 231 | 清空链表,即使链表只剩下头节点(头节点中没有数据) 232 | */ 233 | void clear_list(PNODE pHead) 234 | { 235 | PNODE p = pHead->pNext; 236 | PNODE r = NULL; 237 | while(p != NULL) 238 | { 239 | r = p->pNext; 240 | free(p); 241 | p = r; 242 | } 243 | pHead->pNext = NULL; 244 | return ; 245 | } 246 | -------------------------------------------------------------------------------- /linux下编译的/roundqueue/roundqueue.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************************************** 2 | 以下为操作队列的算法,该队列为静态队列,用循环数组实现。 3 | 给该队列分配的内存长度为len+1,但实际只用了len个内存空间来保存数据,这样做是为了更方便判断队列的满与空。 4 | 队列中front位置中存放的是队首的数据,rear位置的前一个位置中存放队尾的数据,而rear位置中则没有数据存放, 5 | 这样做的目的是为了在入队和出队时方便对队列的操作,而不用考虑特殊情况 6 | **********************************************************************************************************/ 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | int len;//全局变量,静态队列的实际有效长度,即实际存放了len个数 13 | typedef struct Queue 14 | { 15 | int *pBase; 16 | int front; 17 | int rear; 18 | } QUEUE,*PQUEUE; 19 | 20 | PQUEUE creat_queue(); 21 | bool enter_queue(PQUEUE,int); 22 | bool full_queue(PQUEUE); 23 | bool empty_queue(PQUEUE); 24 | void traverse_queue(PQUEUE); 25 | bool out_queue(PQUEUE,int *); 26 | 27 | int main() 28 | { //创建静态队列,并定义出队数据的保存在变量data_save中 29 | int data_save; 30 | PQUEUE pQueue = creat_queue(); 31 | //将数据入队,并遍历输出队列中的数据 32 | enter_queue(pQueue,1); 33 | enter_queue(pQueue,2); 34 | enter_queue(pQueue,3); 35 | enter_queue(pQueue,4); 36 | traverse_queue(pQueue); 37 | //将数据出队,并遍历输出队列中的数据 38 | out_queue(pQueue,&data_save); 39 | traverse_queue(pQueue); 40 | 41 | return 0; 42 | } 43 | 44 | /* 45 | 创建并初始化一个空的静态队列,返回指向该队列的指针,此时首尾在队列同一位置处 46 | */ 47 | PQUEUE creat_queue() 48 | { 49 | printf("Input the length of the queue:\n"); 50 | scanf("%d",&len); 51 | PQUEUE pQueue = (PQUEUE)malloc(sizeof(QUEUE)); 52 | pQueue->pBase = (int *)malloc(sizeof(int)*(len+1)); 53 | if(NULL==pQueue || NULL==pQueue->pBase) 54 | { 55 | printf("malloc failed!"); 56 | exit(-1); 57 | } 58 | else 59 | { 60 | pQueue->front = 0; 61 | pQueue->rear = 0; 62 | } 63 | return pQueue; 64 | } 65 | 66 | /* 67 | 判断该静态队列是否满 68 | */ 69 | bool full_queue(PQUEUE pQueue) 70 | { 71 | if(pQueue->front == (pQueue->rear+1)%(len+1)) 72 | return true; 73 | else 74 | return false; 75 | } 76 | 77 | /* 78 | 判断该静态队列是否空 79 | */ 80 | bool empty_queue(PQUEUE pQueue) 81 | { 82 | if(pQueue->front == pQueue->rear) 83 | return true; 84 | else 85 | return false; 86 | } 87 | 88 | /* 89 | 将变量val从队尾入队 90 | */ 91 | bool enter_queue(PQUEUE pQueue,int val) 92 | { 93 | if(full_queue(pQueue)) 94 | return false; 95 | else 96 | { 97 | pQueue->pBase[pQueue->rear] = val; 98 | pQueue->rear = (pQueue->rear+1)%(len+1); 99 | return true; 100 | } 101 | } 102 | 103 | /* 104 | 将数据出队,并将其保存在out_data指针指向的位置 105 | */ 106 | bool out_queue(PQUEUE pQueue,int *out_data) 107 | { 108 | if(empty_queue(pQueue)) 109 | return false; 110 | else 111 | { 112 | *out_data = pBase[pQueue->front]; 113 | pQueue->front = (pQueue->front+1)%(len+1); 114 | return true; 115 | } 116 | } 117 | 118 | /* 119 | 遍历该静态队列,并自队首向队尾输出队列中的数据 120 | */ 121 | void traverse_queue(PQUEUE pQueue) 122 | { 123 | if(empty_queue(pQueue)) 124 | printf("there on datas in the queue!\n"); 125 | else 126 | { 127 | int i = pQueue->front; 128 | printf("now datas in the queue are:\n"); 129 | while(i != pQueue->rear) 130 | { 131 | printf("%d ",pQueue->pBase[i]); 132 | i = (i+1)%(len+1); 133 | } 134 | printf("\n"); 135 | } 136 | 137 | return ; 138 | } 139 | 140 | -------------------------------------------------------------------------------- /linux下编译的/sort/quicksort.c: -------------------------------------------------------------------------------- 1 | /********************** 2 | 快速排序算法,以升序为例 3 | **********************/ 4 | 5 | #include 6 | 7 | void quickSort(int *,int,int); 8 | int findPoss(int *,int,int); 9 | 10 | int main() 11 | { 12 | int i; 13 | int arry[] = {8,9,0,-3,6,7,-11}; 14 | 15 | quickSort(arry,0,6); 16 | 17 | printf("After sorted:\n"); 18 | for(i=0;i<7;i++) 19 | printf("%d ",arry[i]); 20 | printf("\n"); 21 | return 0; 22 | } 23 | 24 | /* 25 | 快速排序函数,通过递归实现 26 | */ 27 | void quickSort(int *a,int low,int high) 28 | { 29 | int pos; 30 | 31 | if(low < high) 32 | { 33 | pos = findPoss(a,low,high); 34 | quickSort(a,low,pos-1); 35 | quickSort(a,pos+1,high); 36 | } 37 | return ; 38 | } 39 | 40 | /* 41 | 该函数返回分割点数值所在的位置,a为待排序数组的首地址, 42 | low刚开始表示排序范围内的第一个元素的位置,逐渐向右移动, 43 | high刚开始表示排序范围内的最后一个位置,逐渐向左移动 44 | */ 45 | int findPoss(int *a,int low,int high) 46 | { 47 | int val = a[low]; 48 | while(low < high) 49 | { 50 | while(low=val) 51 | high--; 52 | a[low] = a[high]; 53 | 54 | while(low 9 | #include 10 | #include 11 | 12 | typedef struct Node 13 | { 14 | int data; 15 | struct Node *pNext; 16 | }NODE,*PNODE; 17 | 18 | typedef struct Stack 19 | { 20 | PNODE pTop; 21 | PNODE pBottom; 22 | }STACK,*PSTACK; 23 | 24 | PSTACK create_stack(); 25 | void push_stack(PSTACK,int); 26 | void traverse_stack(PSTACK); 27 | bool pop_stack(PSTACK,int *); 28 | bool is_empty(PSTACK); 29 | void clear_stack(PSTACK); 30 | 31 | int main() 32 | { 33 | int data_pop; 34 | //创建一个空的栈,pS指针指向该栈 35 | PSTACK pS = create_stack(); 36 | 37 | //向该栈中压入数据,遍历该栈并输出栈中的数据 38 | push_stack(pS,2); 39 | push_stack(pS,6); 40 | push_stack(pS,28); 41 | traverse_stack(pS); 42 | 43 | //从该栈中推出数据,遍历该栈并输出栈中的数据 44 | if(pop_stack(pS,&data_pop)) 45 | printf("pop succeed,the data poped out is:%d\n",data_pop); 46 | else 47 | printf("pop failed\n"); 48 | traverse_stack(pS); 49 | 50 | //清空栈,遍历该栈并输出栈中的数据 51 | clear_stack(pS); 52 | printf("data cleared!\n"); 53 | traverse_stack(pS); 54 | 55 | return 0; 56 | } 57 | 58 | /* 59 | 创建一个空栈,并返回指向该栈的指针 60 | */ 61 | PSTACK create_stack() 62 | { 63 | PSTACK pS = (PSTACK)malloc(sizeof(STACK)); 64 | pS->pTop = (PNODE)malloc(sizeof(NODE)); 65 | if(NULL==pS || NULL==pS->pTop) 66 | { 67 | printf("malloc failed"); 68 | exit(-1); 69 | } 70 | else 71 | { 72 | pS->pBottom = pS->pTop; 73 | pS->pBottom->pNext = NULL; 74 | } 75 | 76 | return pS; 77 | } 78 | 79 | /* 80 | 判断该栈是否为空 81 | */ 82 | bool is_empty(PSTACK pS) 83 | { 84 | if(pS->pTop == pS->pBottom) 85 | return true; 86 | else 87 | return false; 88 | } 89 | 90 | /* 91 | 向pS指针指向的栈中压入数据val 92 | */ 93 | void push_stack(PSTACK pS,int val) 94 | { 95 | PNODE pNew = (PNODE)malloc(sizeof(NODE)); 96 | if(NULL==pNew) 97 | { 98 | printf("malloc failed"); 99 | exit(-1); 100 | } 101 | else 102 | { 103 | pNew->data = val; 104 | pNew->pNext = pS->pTop; 105 | pS->pTop = pNew; 106 | } 107 | return ; 108 | } 109 | 110 | /* 111 | 从栈中推出数据,并将推出的数据保存在pData指针所指向的位置 112 | */ 113 | bool pop_stack(PSTACK pS,int *pData) 114 | { 115 | if(is_empty(pS)) 116 | return false; 117 | else 118 | { 119 | PNODE p = pS->pTop; 120 | *pData = p->data; 121 | pS->pTop = p->pNext; 122 | free(p); 123 | p = NULL; 124 | return true; 125 | } 126 | } 127 | 128 | /* 129 | 遍历栈,并自栈顶向栈底输出栈中的数据 130 | */ 131 | void traverse_stack(PSTACK pS) 132 | { 133 | PNODE pCurrent = pS->pTop; 134 | printf("Now datas int the stack are:\n"); 135 | while(pCurrent != pS->pBottom) 136 | { 137 | printf("%d ",pCurrent->data); 138 | pCurrent = pCurrent->pNext; 139 | } 140 | printf("\n"); 141 | return ; 142 | } 143 | 144 | /* 145 | 清空栈,即将其还原为空栈 146 | */ 147 | void clear_stack(PSTACK pS) 148 | { 149 | if(is_empty(pS)) 150 | return ; 151 | else 152 | { 153 | PNODE p = pS->pTop; 154 | PNODE r = NULL; 155 | while(p != pS->pBottom) 156 | { 157 | r = p->pNext; 158 | free(p); 159 | p = r; 160 | } 161 | pS->pTop = pS->pBottom; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /二叉排序树/BST.CPP: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/二叉排序树/BST.CPP -------------------------------------------------------------------------------- /二叉树/二叉树的递归遍历/二叉树遍历的递归实现.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/二叉树/二叉树的递归遍历/二叉树遍历的递归实现.cpp -------------------------------------------------------------------------------- /二叉树/二叉树遍历的非递归实现/data_structure.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/二叉树/二叉树遍历的非递归实现/data_structure.h -------------------------------------------------------------------------------- /二叉树/二叉树遍历的非递归实现/stack_mthod.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/二叉树/二叉树遍历的非递归实现/stack_mthod.cpp -------------------------------------------------------------------------------- /二叉树/二叉树遍历的非递归实现/traverse_tree.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/二叉树/二叉树遍历的非递归实现/traverse_tree.cpp -------------------------------------------------------------------------------- /二叉树/二叉树遍历的非递归实现/tree_method.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/二叉树/二叉树遍历的非递归实现/tree_method.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/check_list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/check_list.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/delete_data.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/delete_data.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/free.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/free.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/input.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/input.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/insert.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/insert.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/itm_count.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/itm_count.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/link_main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/link_main.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/show.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/show.cpp -------------------------------------------------------------------------------- /单链表/单链表无头结点版/sll_node.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/sll_node.h -------------------------------------------------------------------------------- /单链表/单链表无头结点版/sort_show.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表无头结点版/sort_show.cpp -------------------------------------------------------------------------------- /单链表/单链表有头结点版/list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/单链表/单链表有头结点版/list.cpp -------------------------------------------------------------------------------- /各种排序/shell排序/shell排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/shell排序/shell排序.cpp -------------------------------------------------------------------------------- /各种排序/冒泡排序/原始冒泡排序/BubbleSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/冒泡排序/原始冒泡排序/BubbleSort.cpp -------------------------------------------------------------------------------- /各种排序/冒泡排序/改进冒泡排序/UpdatedBubbleSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/冒泡排序/改进冒泡排序/UpdatedBubbleSort.cpp -------------------------------------------------------------------------------- /各种排序/基数排序/BasicSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/基数排序/BasicSort.cpp -------------------------------------------------------------------------------- /各种排序/堆排序/HeapSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/堆排序/HeapSort.cpp -------------------------------------------------------------------------------- /各种排序/归并排序/我实现的代码/MergeSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/归并排序/我实现的代码/MergeSort.cpp -------------------------------------------------------------------------------- /各种排序/归并排序/经典实现代码/MergeSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/归并排序/经典实现代码/MergeSort.cpp -------------------------------------------------------------------------------- /各种排序/快速排序/QuickSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/快速排序/QuickSort.cpp -------------------------------------------------------------------------------- /各种排序/插入排序/折半插入排序/折半插入排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/插入排序/折半插入排序/折半插入排序.cpp -------------------------------------------------------------------------------- /各种排序/插入排序/直接插入排序/插入排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/插入排序/直接插入排序/插入排序.cpp -------------------------------------------------------------------------------- /各种排序/计数排序/CountSort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/计数排序/CountSort.cpp -------------------------------------------------------------------------------- /各种排序/选择排序/Select_Sort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/各种排序/选择排序/Select_Sort.cpp -------------------------------------------------------------------------------- /哈希表/data_structure.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/哈希表/data_structure.h -------------------------------------------------------------------------------- /哈希表/function_hash.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/哈希表/function_hash.cpp -------------------------------------------------------------------------------- /哈希表/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/哈希表/main.cpp -------------------------------------------------------------------------------- /图的遍历/data_structure.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/图的遍历/data_structure.h -------------------------------------------------------------------------------- /图的遍历/function_graph.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/图的遍历/function_graph.cpp -------------------------------------------------------------------------------- /图的遍历/function_queue.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/图的遍历/function_queue.cpp -------------------------------------------------------------------------------- /图的遍历/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/图的遍历/main.cpp -------------------------------------------------------------------------------- /数组循环移位/循环右移算法/Cpp1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/数组循环移位/循环右移算法/Cpp1.cpp -------------------------------------------------------------------------------- /数组循环移位/循环左移算法/数组循环左移.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/数组循环移位/循环左移算法/数组循环左移.cpp -------------------------------------------------------------------------------- /模式匹配 BF—KMP/BF算法/simple_index.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/模式匹配 BF—KMP/BF算法/simple_index.cpp -------------------------------------------------------------------------------- /模式匹配 BF—KMP/KMP算法/kmp_index.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/模式匹配 BF—KMP/KMP算法/kmp_index.cpp -------------------------------------------------------------------------------- /链式栈/Stack.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/链式栈/Stack.cpp -------------------------------------------------------------------------------- /链式队列/链式队列.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mmc-maodun/Data-Structure-And-Algorithm/36b22837fe383b5d8b8e1b781528ea8e31b25795/链式队列/链式队列.cpp --------------------------------------------------------------------------------