K阶斐波那契数列--------西工大NOJ习题.10 原创不易,转载请说明出处!!! 科普:k阶斐波那契数列的0到n-1项需要有初始值. 其中,0到n-2项初始化为0,第n-1项初始化为1. 在这道题目中,所引用的函数详见:数据结构实现--循环队列 (我的一篇博文) 我使用的方法是尺取法,这样可以大大地减小时间复杂度. 具体见代码: #include <stdio.h> #include <stdlib.h> typedef int Elem; typedef struct Qu…
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> typedef struct _Queue { int max_size; int rear; int lenth; int* data; }Queue; Queue* Create(int n) { Queue* Q = (Queue*)malloc(sizeof(Queue)); Q->data = (int*)calloc(n,…
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef enum{ATOM, LIST}ElemType; typedef struct GLNode{ ElemType tag; union{ char atom; struct{ struct GLNode *hp,*tp; }htp; }atom_htp; }GLNode; char s[1000]; void Process(char…
需要注意的点:在创建二叉树的函数中,如果len1==len2==0,一定要把(*T)置为NULL然后退出循环 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct TreeNode { char data; struct TreeNode* LChild, *RChild; }TreeNode; void Create(TreeNode** T, char *s1, int l…
二叉排序树的合并有三种方法 先存入数组,然后..... 直接在第二个树上添加第一个数的元素,时间复杂度为O(NlogN) 就像是合并数组一样合并二叉排序树,分别扫描,时间复杂度极低. 第三种我写了一下,是错误的答案,实在想不出更好的方法. 网上还有按照方法1进行... 方法二可能更加正常一点,虽然时间复杂度比方法一大... 代码 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef stru…
题解 这道题目说的很诡异,其实没有什么把括号补上....仅仅是先序读入,然后中序输出就行了 代码 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct TreeNode { char data; struct TreeNode *LChild, *RChild; }TreeNode; char *c; void Create(TreeNode **T) { if(*c=='#'…
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct TreeNode { char data; struct TreeNode *LChild, *RChild; }TreeNode; void Create(TreeNode **T, char *s, int len) { if(len==1) { (*T) = (TreeNode*)malloc(sizeof(TreeN…
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> typedef int ElemType; typedef struct Node { int row, col; ElemType data; struct Node* right, * down; }Node; typedef struct CrossLink { Node* row_head;//注意:这是头结点数组 Node* col…
目录 代码 代码 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct ArcNode{ int to; struct ArcNode *next; int w; }ArcNode; typedef struct VertexNode { int data; ArcNode *arc; }VertexNode; typedef struct Graph { int max; V…
​ 代码 代码 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct ArcNode{ int to; struct ArcNode *next; int w; }ArcNode; typedef struct VertexNode { int data; ArcNode *arc; }VertexNode; typedef struct Graph { int max; Ve…