![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
栈
AlexCookie
感谢互联网,让我在知识的海洋遨游,感谢广大网友,把所学知识分享,咱们一起进步!博主主分享:算法,计算机方向。
展开
-
后序遍历的非递归形式的算法。
后序遍历的非递归形式的算法。/*后序遍历的非递归形式的算法。 */#include <stdio.h>#include <malloc.h>//用来申请二叉树结点空间 #include <stack>using namespace std;//std空间 typedef struct node{ char data; int flag;//结点是否入过栈 标识 ,初始为0 struct node* lchild; struct node.原创 2021-12-04 22:54:47 · 1699 阅读 · 0 评论 -
根据用户输入的偶对(以输入0表示结束)建立其有向图的邻接表,并输出其一个拓扑排序序列和逆拓扑排序,并判断是否有回路
根据用户输入的偶对(以输入0表示结束)建立其有向图的邻接表,并输出其一个拓扑排序序列和逆拓扑排序,并判断是否有回路top代码://拓扑排序int top[size] = {0};//保存 拓扑排序结果 方便逆拓扑 int topsort(listnode a[]){ stack<int>s1; node *q; for(int i = 0;i < size;i ++) { if(a[i].indegree == 0)//遍历表结点,所有入度为0的都进栈 .原创 2021-11-20 15:17:17 · 1097 阅读 · 0 评论 -
实现按层次遍历二叉树
实现按层次遍历二叉树主要代码:void sequence(blink bt){ queue<blink> s; s.push(bt); while(s.empty() == 0)//该函数返回0说明不为空(为空 会返回1) { printf("%c",s.front()->data);//打印 将出队结点 的元素值 s.push(s.front()->lchild); //左孩子 进队 s.push(s.front()->rchi...原创 2021-11-18 19:59:48 · 589 阅读 · 0 评论 -
编写算法,用归并排序方法实现对整型数组a[n]的 升序排序。
/*编写算法,用归并排序方法实现对整型数组a[n]的 升序排序。*/#include <stdio.h>#include <iostream>#define n 10using namespace std;int a[n] = {9,2,3,3,2,1,6,5,4,10};// n == 10 保存 最后 结果 //分治 思想 考虑 递归算法 void merge_manage(int a[],int begin,int mid,int end){...原创 2021-11-07 22:53:07 · 1150 阅读 · 0 评论 -
实现出栈入栈,输出相反次序
自定义函数 实现 出栈 入栈,输入 一段 序列(以 -1 为结束标志),并 按照与输入相反的次序输出,用栈来实现 这一功能/*自定义函数 实现 出栈 入栈,输入 一段 序列(以 -1 为结束标志),并 按照与输入相反的次序输出,用栈来实现 这一功能 */#include <iostream>#include <stdio.h>//#include <stack> //当然也可直接调用 stack库 #define MaxsizeStack 3原创 2021-10-30 20:32:21 · 822 阅读 · 1 评论