
数据结构
董成荣
每天努力一点点,直到永远
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
链表练习代码
#include #include typedef int element; typedef int Status; #define OK 1 #define ERROR 0 typedef struct LinkNode { element data; struct LinkNode *next; }LinkNode,*LinkedList; Status init(Link原创 2017-05-11 12:41:26 · 336 阅读 · 0 评论 -
二叉树、树、森林之间的转化
树转二叉树将孩子作为左孩子,将第一个兄弟作为右孩子二叉树转树将左孩子的右孩子作为自己的孩子森林转二叉树与转树差不多,唯一需要注意的是要把第二棵树的根节点作为第一棵树的一个兄弟二叉树转森林把右孩子断开成一棵新树的根节点,其他的与转树相同原创 2017-06-28 09:40:03 · 429 阅读 · 0 评论 -
希尔排序练习代码
#include void sort(int A[],int n) { int i,j,tmp,increment; for(increment=n/2;increment>0;increment/=2) { for(i=increment;i<n;i++) { tmp=A[i]; for(j原创 2017-06-28 08:59:39 · 398 阅读 · 0 评论 -
插入排序练习代码
#include void sort(int A[],int n) { int i,j,tmp; for(i=1;i<n;i++) { tmp=A[i]; for(j=i;j>0;j--) { if(tmp<A[j-1]) A[j]=A[j-1];原创 2017-06-28 08:52:20 · 332 阅读 · 0 评论 -
用散列表实现输入拼音输出大写英文字母的功能
我本来是想实现输入拼音输出汉字的功能,可是,好像是因为C语言只能识别256个ASCII码,所以出现了乱码现象,所以我不得已把汉字改成了大写英文字母。 实现的关键是哈希函数,这里因为我只是做练习而不是真正的项目开发,所以我只开了一个大小为11的数组用来存储数据。 我的哈希函数是将字符串的各位变成整数(减去‘a')并相加,最后得到的整数再除以素数11,。这样一个映射关系就成型了,根据测试,作原创 2017-06-12 17:00:59 · 1064 阅读 · 0 评论 -
二叉查找树练习代码
#include #include #define Element int typedef struct Node{ Element data; struct Node *left,*right; }Node,*SearchTree; void init(SearchTree &T) { T=NULL; } SearchTree makeEmpty(SearchTr原创 2017-06-23 16:33:32 · 361 阅读 · 0 评论 -
简单选择排序
与冒泡排序相反,每次把最小的(升序)放到第一个,共放置n-1次 #include void sort(int A[],int N) { for(int i=0;i<N-1;i++) { for(int j=i+1;j<N;j++) { if(A[j]<A[i]) {原创 2017-06-23 15:11:12 · 336 阅读 · 0 评论 -
不带头结点的单链表逆置操作
reverse函数负责逆置工作 #include #include typedef struct Node { int data; struct Node *next; }Node,*List; void init(List &L) { L=(List)malloc(sizeof(Node)); L=NULL; } void insert(List &L,i原创 2017-06-29 21:37:31 · 9872 阅读 · 0 评论 -
最小堆练习代码
#include #include #define INF (-100000) #define MinData 10 typedef int Element; typedef struct Node { int capacity; //容量 int size; //大小 Element *data; //数据域 }Node,*Heap; Heap init(in原创 2017-06-29 16:16:55 · 424 阅读 · 0 评论 -
队列练习代码
#include #include #include const int maxn=100000; int n; typedef struct Node { int front,rear; int size; long long *data; }Queue; void init(Queue &q) { q.size=maxn; q.front=q.re原创 2017-05-11 12:58:21 · 433 阅读 · 0 评论 -
栈练习代码
#include #include const int maxn=1000; typedef struct Node { int *data; int size; int top; }Stack; void init(Stack &s) { s.data=(int *)malloc(sizeof(int)*maxn); s.size=maxn;原创 2017-05-11 12:56:54 · 300 阅读 · 0 评论 -
无根树转有根数
#include #include #include using namespace std; const int maxn = 1000 + 10; vector G[maxn]; //记录无根树(即多条边) int p[maxn]; //某一节点的父节点,-1代表没有节点 //读取无根树 void read_tree() { int u,v,n; printf("请原创 2017-11-15 20:30:29 · 722 阅读 · 0 评论