数据结构与算法分析
文章平均质量分 70
zhenzhenjiajia888
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
双向链表
//双向链表的基本操作 #include using namespace std; typedef struct DLnode { int num; struct DLnode *prior;//前驱指针 struct DLnode *next;//后驱指针 }NODE,*PNODE; //创建双向链表 PNODE creat_() { PNODE head,p,原创 2016-08-23 22:37:11 · 293 阅读 · 0 评论 -
使用链表的基本操作
//动态链表 #include typedef struct node { int a; struct node *next; }NODE,*PNODE; //构建链表 PNODE creat_() { PNODE head,q,p;//定义头指针head,代替头指针球q(头指针不能动) head=(PNODE)malloc(sizeof(NODE));//分配内原创 2016-08-23 16:05:31 · 290 阅读 · 0 评论 -
线索二叉树
线索二叉树方便了寻找前驱和后继 //0 为link,1为thread #include #include using namespace std; typedef struct node { char data; struct node* lchild; struct node* rchild; int ltag,rtag; }bitnode,*bitree;原创 2016-09-07 18:31:57 · 374 阅读 · 0 评论 -
构建表达式树
方法输入后缀表达式,如果输入的是中缀表达式,则利用栈,转换成后缀表达式,然后检测每一个输入字符,如果操作数,则把该数的地址压入栈中,如果是操作符,则把栈的栈顶元素和栈顶元素的下一个元素出栈,分别为操作符的左子树和右子树,然后把该操作符的地址压入栈中,最后中序递归输出 #include #include #include using namespace std; typedef struct原创 2016-09-18 18:19:12 · 1082 阅读 · 0 评论 -
二叉查找树的操作
概念:使二叉树变成二叉查找树的性质是,对于树中的每个结点x,它的左子树中所有关键字值小于x的关键字值,而它的右子树中所有关键字的值大于x的关键字值 先序输入 typedef struct bitnode { int data;//对于数字的输入注意对于每个数字之间的空格如果是字符的话就不用空格把每个字符分开 struct bitnode* lchild; struct原创 2016-09-18 21:07:43 · 410 阅读 · 0 评论 -
汉诺塔递归算法
点击打开链接原创 2016-08-26 19:34:46 · 437 阅读 · 0 评论 -
二叉树
/*测试数据 ABD#G###CE##F##*/ #include #include using namespace std; typedef struct node { char data; struct node* lchild; struct node* rchild; }*bitree,bitnode; typedef struct qstack {原创 2016-09-05 22:34:22 · 377 阅读 · 0 评论 -
二叉树的各种遍历
#include #include using namespace std; typedef struct node { char data; struct node* lchild; struct node* rchild; }*bitree,bitnode; typedef struct qstack { bitree *base;//存储bitree指针原创 2016-09-05 18:38:14 · 325 阅读 · 0 评论 -
对于链表,栈,队列,树函数参数的理解(未完)
对于最近学习的链表,栈,队列,二叉树(基础)的函数参数有了更深的理解。 对于这几个数据结构,可以采用静态,或者是链式存储和操作,但是它们函数的参数却是不一样的。 对于一些链式存储和操作的,有3种方法来返回头指针 1 在函数外新建头指针,然后函数返回头指针 2 用二级指针 3 用参数的引用(效果和二级指针一样) 链表(静态): typedef struct list { int原创 2016-09-05 18:34:39 · 400 阅读 · 0 评论 -
二叉树的层次遍历
层次遍历二叉树,关键要用到队列,父结点一出,就要判断子结点是否为空,非空则马上进入队列 #include #include using namespace std; typedef struct bitnode { char data; struct bitnode *lchild; struct bitnode *rchild; }bitnode,*bitree;原创 2016-09-17 17:23:05 · 278 阅读 · 0 评论 -
顺序栈的基本操作
#include #include #define space 20 using namespace std; typedef struct stack { int* base;//数组 int top; int stacksize;//长度 }qstack; void init(qstack &s,int size) { s.base=(int*)malloc原创 2016-08-25 18:24:49 · 709 阅读 · 0 评论 -
顺序表应用-集合的表示与实现
#include using namespace std; typedef struct list { int *base; int lengh; int listsize; }qlist; //创建 void creat_(qlist &l,int n) { l.base=(int*)malloc(n*sizeof(int)); if(l.base==原创 2016-08-24 15:24:19 · 639 阅读 · 0 评论 -
链表—约瑟夫环
#include #include typedef struct node { int num; struct node* next; }NODE,*PNODE; PNODE creat_(int n) { PNODE head,p,q; int num_=1; head=(PNODE)malloc(sizeof(NODE)); head->n原创 2016-08-24 20:41:51 · 377 阅读 · 0 评论 -
链表求一元函数和
// #include #include using namespace std; struct node { int coefficient; int exponent; struct node *next; }; struct node *creat()//建立单链表返回链表头指针,此头指针无数据 { struct node *head,*p1,*p2;原创 2016-08-22 13:04:09 · 306 阅读 · 0 评论 -
广义表头尾链表(未完)
#include #include #include #include #define MAX 225 using namespace std; typedef unsigned char Sstring [MAX+1]; typedef enum{ATOM,LIST}eleflag; typedef struct node { eleflag tag; union原创 2016-09-03 15:34:12 · 659 阅读 · 0 评论 -
后缀表达式/中缀到后缀表达式
输入空格跳出循环 while((k=getchar())!='\n') { a[i]=k; i++; }原创 2016-08-27 09:07:44 · 423 阅读 · 0 评论 -
串的动态存储操作
该算法虽然是使用动态内存分配的方法实现,但因其存储单元的地址是连续的,所以本质上还是属于顺序存储。 #include #include #include #define MAX 225 using namespace std; typedef struct { char* base; int lengh; }qstring,*pstring; /**************原创 2016-08-31 19:22:03 · 582 阅读 · 0 评论 -
树、森林和二叉树的转换
文章来自:http://www.cnblogs.com/zhuyf87/archive/2012/11/04/2753950.html原创 2016-09-13 17:53:44 · 242 阅读 · 0 评论 -
串的静态顺序存储基本操作
在C语言中没有专门的字符串变量,通常用一个字符数组来存放一个字符串。字符串总是以'\0'作为串的结束符。因此当把一个字符串存入一个数组时,也把结束符 '\0'存入数组,并以此作为该字符串是否结束的标志。有了'\0'标志后,就不能再用字符数组的长度来判断字符串的长度了。 #include #include #define MAXSIZE 225 using namespace std; t原创 2016-08-31 17:38:35 · 1021 阅读 · 0 评论 -
KMP
#include #include #define MAX 225 using namespace std; typedef unsigned char Sstring[MAX+1]; void init(Sstring &s) { int i; char str[100]; cin>>str; for(i=1;str[i]!='\0';i++) {原创 2016-09-01 17:31:41 · 247 阅读 · 0 评论 -
基数求和
void radixSort(int *a,int size) { int temp[10][5]={0}; //第一个10表示0到9位数字,第二个20表示a的size int order[10]={0}; int i,j,k; //k表示当前比较的那一位上的具体数字 int n; int p; n=1; while(n <= 100)//由原创 2016-08-22 13:03:03 · 500 阅读 · 0 评论 -
haffuman树
#include #include using namespace std; //哈夫曼树的存储表示 typedef struct { int weight; // 权值 int parent, lChild, rChild; // 双亲及左右孩子的下标 }HTNode, *HuffmanTree; // 选择权值最小的两颗树 void SelectMin(H原创 2016-09-08 20:59:01 · 749 阅读 · 0 评论 -
斐波那契
普通算法和当n大于50或者更大的时候的算法优化 http://blog.csdn.net/woshisap/article/details/7566946原创 2016-08-30 16:04:12 · 254 阅读 · 0 评论 -
基数排序(链表)
#include using namespace std; typedef struct Node { int data; struct Node *next; }LNode; void Initiate(LNode **head) { (*head)=(LNode*)malloc(sizeof(LNode)); (*head)->next=NULL; } v原创 2016-08-29 19:17:15 · 1022 阅读 · 0 评论 -
链式栈的基本操作
#include #include //bool的使用 #include typedef struct node { int num; struct node * next; }NODE, *sNODE; typedef struct stack { sNODE top; sNODE botton; }STACK,*sSTACK; //建立空栈 void ini原创 2016-08-22 13:04:55 · 774 阅读 · 0 评论 -
关于指针和地址的问题///////
当定义栈,链表,队列的时候,参数的传递可食 pstack 或 qstack &s,但是不管如何定义参数,实参都需要定义成qstack s,使用时如果是第一个形参,则需要加&,否则不需要加&原创 2016-08-28 14:59:49 · 402 阅读 · 0 评论 -
队列的使用(动态)
#include #include #include using namespace std; typedef struct node//链式队列结点类型 { int num; struct node* pnext; }qnode,*pnode; typedef struct queue//链式队列类型 { pnode front; pnode rear; }原创 2016-08-28 10:54:59 · 462 阅读 · 0 评论 -
队列的使用(静态数组)
#include #include #include using namespace std; typedef struct queue { int* base; int front; int rear; }queue; //初始化 void init(queue &q,int size) { q.base=(int*)malloc(size*sizeof(i原创 2016-08-27 23:00:49 · 398 阅读 · 0 评论 -
循环链表(两个单链表组合成一个循环链表)
//动态链表 #include #include typedef struct node { int a; struct node *next; }NODE,*PNODE; //构建链表 PNODE creat_() { PNODE head,q,p;//定义头指针head,代替头指针球q(头指针不能动) head=(PNODE)malloc(sizeof(NO原创 2016-08-23 22:51:50 · 1348 阅读 · 0 评论 -
栈的应用-括号的匹配
#include #include #include using namespace std; typedef struct node { char AL; struct node* next; }qnode,*pnode; typedef struct stack { pnode top; pnode botton; }qstack,*pstack; voi原创 2016-08-25 20:18:33 · 338 阅读 · 0 评论
分享