
数据结构
文章平均质量分 81
同学少年
没有什么不可能!
展开
-
[数据结构] 表达式求值(转化为后缀表达式再求值或直接求值)
两种情况:1. 根据输入的算数表达式,如(56-20) /(4+2), 先转化为后缀表达式(逆波兰式)56#20#-4#2#+/ 因为输入的数字有多位数的(56),所以数之间用#隔开,然后根据后缀表达式求值。2.根据输入的算数表达式,直接进行求值。对于情况1:转化为后缀表达式时用到了一个符号栈,把后缀表达式存放到数组postExp中,根据后缀表达式求值时用到了一个运算数栈原创 2016-03-05 17:23:04 · 5278 阅读 · 0 评论 -
[ACM] sdut 2882 Full Binary Tree (满二叉树的公共祖先)
Full Binary TreeTime Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^题目描述In computer science, a binary tree is a tree data structure in which each node has at most two children原创 2014-11-27 19:23:17 · 2176 阅读 · 0 评论 -
[ACM] POJ 2442 Sequence (堆的性质)
解题思路: 有m行,每行n个数,从每行中取出一个数相加一起求出sum,这样的sum有n的m次方个。要求的前n个最小的sum值。第一次使用STL里面的堆,一开始对pop_heap()有点不太理解,后来明白了,比如对数组heap[n],最大下标为n-1建堆,默认的是建立大顶堆,heap[0]是数组中最大的数,写一条pop_heap()语句,就是把heap[0]和 heap[n原创 2014-07-17 20:18:59 · 2216 阅读 · 1 评论 -
[ACM] POJ 3295 Tautology (构造)
TautologyTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 9302 Accepted: 3549DescriptionWFF 'N PROOF is a logic game played with dice. Each die has six原创 2014-07-14 16:33:34 · 1797 阅读 · 0 评论 -
[ACM] POJ 3349 Snowflake Snow Snowflakes(哈希查找,链式解决冲突)
Snowflake Snow SnowflakesTime Limit: 4000MS Memory Limit: 65536KTotal Submissions: 30512 Accepted: 8024DescriptionYou may have heard that no two snowflakes are al原创 2014-07-12 17:37:17 · 2559 阅读 · 4 评论 -
[数据结构] 二叉树的建立及其基本操作
如图:代码: #include #include #include #include using namespace std;char ch;typedef struct BinNode{ char data; struct BinNode *lchild,*rchild;}BinNode,*BinTree; //二叉树链式原创 2014-05-28 19:16:32 · 5486 阅读 · 1 评论 -
[数据结构] KMP字符串匹配
采用了next[0]=-1的形式,字符串开始位置都是从0开始代码:#include #include #include using namespace std;const int maxn=110;int next[maxn];int nextval[maxn];string s1;//主串string s2;//模式串int len1;//主串的长度原创 2014-05-14 19:09:16 · 1738 阅读 · 0 评论 -
[数据结构] 迷宫问题(栈和队列,深搜和广搜)
代码:#include #include #include #include #include using namespace std;int dx[4]={0,-1,1,0};//方向int dy[4]={-1,0,0,1};bool vis[6][6];int total=0;//多少可到达路径int sx=1,sy=1;//入口出口坐标int ex=4,ey=4;原创 2014-04-26 12:55:24 · 3661 阅读 · 0 评论 -
[数据结构] N皇后问题
代码:#include #include #include using namespace std;const int N=100;int c[N];//皇后第i行放在第几列上int n,total;int cc;//方法数void dfs(int cur){ if(cur>n) { cout<<"第"<<cc++<<"种方法:"<<endl原创 2014-04-26 12:52:45 · 2570 阅读 · 1 评论 -
队列逆置
思路:用一个栈起到过渡的作用。先将队列中的元素放入栈中,然后初始化队列,再将元素从栈中取出放到初始化的队列中。代码:#include #include #include using namespace std;const int maxn=10;typedef struct{ char data[maxn]; int front,rear原创 2014-04-05 14:34:08 · 3656 阅读 · 0 评论 -
[ACM] 括号匹配问题(栈的使用)
括号配对问题时间限制:3000 ms | 内存限制:65535 KB难度:3描述 现在,有一行括号序列,请你检查这行括号是否配对。输入 第一行输入一个数N(0<N<=100),表示有N组测试数据。后面的N行输入多组输入数据,每组输入数据都是一个字符串S(S的长度小于10000,且S不是空串),测试数据组数少于5组。数据保证S中只含有"[","]","(",")"原创 2014-04-05 13:18:47 · 4992 阅读 · 0 评论 -
环形队中实现队列的基本运算
/*队空条件:front=rear队满条件:(rear+1)%MaxSize=front进队e操作:rear=(rear+1)%MaxSize; 将e放在rear处出队操作:front=(front+1)%MaxSize;取出front处元素e; */#include #include using namespace std;const int maxn=4;t原创 2014-04-02 19:17:33 · 2833 阅读 · 0 评论 -
队列的顺序存储结构及其基本运算的实现
代码:#include #include using namespace std;const int maxn=500;typedef struct{ int data[maxn]; int front,rear;}queue;//初始化队列void init(queue *&q){ q=(queue*)malloc(s原创 2014-04-02 18:56:20 · 2710 阅读 · 0 评论 -
栈的链式存储结构及其基本运算实现
#include #include using namespace std;typedef struct linknode{ int data; struct linknode *next;}Listack;//初始化栈void init(Listack *&s){ s=(Listack*)malloc(sizeof(Lista原创 2014-04-02 18:21:10 · 1969 阅读 · 0 评论 -
栈的顺序存储结构及其基本运算实现
#include #include using namespace std;const int maxn=500;typedef struct { int data[maxn]; int top;}Stack;//初始化stackvoid init(Stack *&s){ s=(Stack *)malloc(sizeof(Stack));原创 2014-04-02 18:20:04 · 2188 阅读 · 0 评论 -
数据结构上机实验:单链表操作
#include #include using namespace std;typedef struct Node{ char c; struct Node *next;}*LinkList,LNode;//初始化单链表hLinkList Init(LinkList &h){ h=(LNode*)malloc(sizeof(LN原创 2014-03-19 21:02:18 · 4252 阅读 · 0 评论