数据结构
橙子@C
这个作者很懒,什么都没留下…
展开
-
数据结构:10大经典排序
排序1、冒泡排序2、选择排序3、插入排序4、希尔排序5、快速排序6、归并排序7、堆排序8、计数排序9、桶排序10、基数排序1、冒泡排序// 冒泡排序#include <stdlib.h>#include <stdio.h>// 采用两层循环实现的方法。// 参数arr是待排序数组的首地址,len是数组元素的个数。void bubblesort1(int *arr,unsigned int len){ if (len<2) return; // 数组小于2个原创 2022-02-02 21:51:27 · 7806 阅读 · 4 评论 -
数据结构:哈希表
/* * 程序名:hash.c,此程序演示哈希表的实现,数据元素单链表带头结点。 * */#include <stdio.h>#include <stdlib.h>#include <string.h>// 哈希表中数据元素的结构体。typedef struct Element{ unsigned int key; // 关键字。 int value; // 数据元素其它数据项,可以是任意...原创 2022-01-31 17:26:08 · 534 阅读 · 0 评论 -
数据结构:查找
/* * 程序名:binsearch.c,此程序演示折半查找。 * */#include <stdio.h>#include <string.h>// 迭代实现。// 在sstable中查找key,失败返回-1,成功返回key在sstable中的数组下标。int Bin_Search1(int *sstable,unsigned int len,int key){ int low,high,mid; low=0; high=le...原创 2022-01-31 11:05:32 · 1154 阅读 · 0 评论 -
数据结构:二叉排序树
/* * C语言版本。 * 程序名:btree4.c,此程序演示二叉排序树的各种操作,包括插入、删除、查找。 **/#include <stdio.h>#include <string.h>#include <stdlib.h>///////////////////////////////////////////////typedef int ElemType; // 自定义数据元素为整数。// 二叉树的数据结构。typedef ...原创 2022-01-23 13:39:18 · 131 阅读 · 0 评论 -
数据结构:二叉树的先序遍历、中序遍历和后续遍历原理和实现
先序遍历中序遍历后续遍历/* * 程序名:btree2.c,此程序演示二叉树的前序遍历、中序遍历和后序遍历,包括递归和非递归两种方法。 * */#include <stdio.h>#include <string.h>#include <stdlib.h>///////////////////////////////////////////////// 二叉树的数据结构。typedef...原创 2022-01-23 11:23:36 · 915 阅读 · 0 评论 -
数据结构:二叉树的层次遍历和实现
/* * 程序名:btree1.c,此程序演示二叉树的层次遍历。 * */#include <stdio.h>#include <string.h>#include <stdlib.h>///////////////////////////////////////////////// 二叉树的数据结构。typedef struct BiTNode{ char data; // 存放结点的数据元素。 struc.原创 2022-01-23 10:12:36 · 491 阅读 · 0 评论 -
数据结构:串(BF和KMP算法)
/* * 程序名:kmp.c,此程序演示了字符串的匹配模式算法,包括: * 1)普通的模式匹配算法,即BF算法; * 2)KMP算法的求next数组; * 3)KMP算法的求nextval数组; * 4)KMP算法的实现。 * */#include <stdio.h>#include <string.h>// 采用BF算法,查找在目标串sstr中模式串tstr出现的位置,字符串的起始位置从0开始。// 只要在目标串sstr中找到了第一个模式串tstr,函数就.原创 2022-01-22 11:44:40 · 856 阅读 · 0 评论 -
数据结构:栈在后缀表达式的应用
/* * 程序名:seqstack3.c,此程序演示用顺序栈实现中缀表达式转后缀表达式。 * */#include <stdio.h>#include <string.h>#define MAXSIZE 100 // 顺序栈的最大长度。 // xxxxxtypedef char ElemType; // 自定义顺序栈的数据元素为字符。 // xxxxtypedef struct{ ElemType data[MA...原创 2022-01-19 21:15:41 · 778 阅读 · 0 评论 -
数据结构:栈在括号匹配中的应用
/* * 程序名:seqstack2.c,此程序演示用顺序栈检查括号是否匹配,支持()[]{}三种括号。 * */#include <stdio.h>#include <string.h>#define MAXSIZE 100 // 顺序栈的最大长度。 // xxxxxtypedef char ElemType; // 自定义顺序栈的数据元素为字符。 // xxxxtypedef struct{ ElemType data...原创 2022-01-19 20:44:15 · 219 阅读 · 0 评论 -
数据结构:队列的链式存储实现
/* * 程序名:linkqueue1.c,此程序演示队列的链表实现(带头结点)。 * #include <stdio.h>#include <string.h>#include <stdlib.h>typedef int ElemType; // 自定义队列的数据元素为整数。typedef struct LNode{ ElemType data; // 存储队列中的元素。 struct LNode *next...原创 2022-01-17 23:13:41 · 663 阅读 · 0 评论 -
数据结构:队列的顺序存储实现
四种实现方案/* * 程序名:seqqueue1.c,此程序演示循环队列的数组实现,队尾指针指向队尾的下一个元素,没有length的辅助变量。 * */#include <stdio.h>#include <string.h>#define MAXSIZE 10 // 循环队列的最大长度,最多可以存放MAXSIZE-1个元素。typedef int ElemType; // 自定义循环队列的数据元素为整数。...原创 2022-01-16 20:11:43 · 718 阅读 · 0 评论 -
数据结构:顺序栈和链栈
/* * 程序名:seqstack1.c,此程序演示顺序栈的实现,数据元素是整数。 * */#include <stdio.h>#include <string.h>#define MAXSIZE 10 // 顺序栈的最大长度。typedef int ElemType; // 自定义顺序栈的数据元素为整数。typedef struct{ ElemType data[MAXSIZE]; // 用数组存储顺序栈中的元素。 int...原创 2022-01-16 19:29:27 · 304 阅读 · 0 评论 -
链表的常用考题
/* * 程序名:linklist6.c,此程序演示链表的常用考题,在linklist1.c上增加了常用考题的解答。 * */#include <stdio.h>#include <string.h>#include <stdlib.h>typedef int ElemType; // 自定义链表的数据元素为整数。typedef struct LNode{ ElemType data; // 存放结点的数据元素。...原创 2022-01-16 18:26:00 · 166 阅读 · 0 评论 -
数据结构:循环单链表原理和实现,循环双链表原理
#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct{ int no; char name[31];}ElemType;typedef struct LNode{ ElemType data; struct LNode *next;}LNode,*LinkList;LNode *InitList1();int PushFront(LinkLi...原创 2022-01-15 20:15:22 · 174 阅读 · 0 评论 -
数据结构:双链表的增删改查
1、单链表注意后面插入的情况,如果是最后一个元素,那么它没有下一个节点的前驱;2、插入:(1)先写该节点的前驱和后继; (2)再写该节点的前驱的后继; (3)在写该节点的后继的前驱;3、删除:(1)注意最后一个节点,如果是最后一个节点,它没有后继的前驱 (2)如果是中间节点,写前驱的后继和后继的前驱;#include<stdio.h>#include<...原创 2022-01-12 22:09:37 · 201 阅读 · 0 评论 -
数据结构:单链表包含(归并)
#include <stdio.h>#include <string.h>#include <stdlib.h>typedef int ElemType; // 自定义链表的数据元素为整数。typedef struct LNode{ ElemType data; // 存放结点的数据元素。 struct LNode *next; // 指向下一个结点的指针。}LNode,*LinkList;// 初始化链表LL,返回值..原创 2022-01-09 18:39:57 · 325 阅读 · 0 评论 -
数据结构:单链表带头结点的增删改查和单链表反转
带头结点和不带头结点的需要注意在元素前插入和删除元素时的判断(while(head->next !=NULL))#include<stdio.h>#include<stdlib.h>#include<string.h>typedef struct{ int no; char name[31];}ElemType;typedef struct LNode{ ElemType data; struct LNode *next..原创 2022-01-09 18:26:29 · 281 阅读 · 0 评论 -
数据结构:顺序表的静态和动态实现
/* * 程序名:seqlist1.c,此程序演示顺序表的静态实现,数据元素是整数。 * */#include <stdio.h>#include <string.h>#define MAXSIZE 100 // 顺序表的最大长度typedef int ElemType; // 自定义顺序表的数据元素为整数。typedef struct{ ElemType data[MAXSIZE]; // 用数组存储顺序表中的元素 unsi.原创 2021-12-26 19:50:14 · 353 阅读 · 0 评论 -
链表的增删该查
#include<stdio.h>#include <stdlib.h>struct test{ int data; struct test *next;};/*打印数据*/void printLink(struct test *head){ int count = 0; while(head != NULL) { count++; printf("NO.%d,data=%d\n",count,.原创 2021-09-11 18:10:13 · 79 阅读 · 0 评论