- 博客(6)
- 资源 (2)
- 收藏
- 关注
原创 数据结构——二叉树建树与遍历
从mooc上看到一张很好的图,说明了前序遍历,中序遍历,后序遍历之间的关系。(1)先序遍历 如果二叉树不为空,访问根节点,前序遍历左子树,前序遍历右子树,如上图×号。//先序遍历 void PreOrderTree(BinTreeNode *root) { if(root) { cout<<root->data<<" "; PreOrderTree(
2017-03-22 20:08:19 742
原创 最长上升子序列(LIS) -最长公共子序列(LCS)
我们可以发现,求整个序列的最长上升子序列长度的子问题是“求以ak(k=1, 2, 3…N)为终点的最长上升子序列的长度”。 我们用max_len(k)表示以ak作为终点的最长上升子序列的长度。 初始状态:max_len(1)=1; 状态转移方程:max_len(k) = max{max_len(i) 1<=i < k 且 ai < ak且 k≠1 } + 1; 若没有符...
2017-03-21 20:04:54 468
原创 Valid Parentheses(用栈实现括号匹配)
问题描述: 输入一行括号 只包括’(’ ‘)’ ‘{’ ‘}’ ‘[’ ‘]’ 如果该字符串中所含的括号是配对的,则输出Yes,如果不配对则输出No。#include <iostream> #include <stack>using namespace std;char change(char i) { if(i == ')') return '('; if(i
2017-03-12 17:04:16 414
原创 数据结构--用C实现链式队列
#include <stdio.h> #include <stdlib.h>typedef struct node { int data; struct node *next; } Node; typedef struct queue { struct node *top; struct node *tail; } Queue;int gettop(struct qu
2017-03-12 15:27:25 353
原创 数据结构 -- 用C实现链式栈
#include <stdio.h> #include <stdlib.h>struct node { int data; struct node *next; }Stack;int gettop(struct node *top) { return top -> data; }struct node * push(struct node *top,int x ) {
2017-03-12 11:27:11 356
原创 HDU 2072 STL
#include <iostream> #include <set> #include <string> #include <sstream>using namespace std;int main() { string str,word; while(getline(cin,str) && str != "#") { istringstream stream
2017-03-02 15:27:26 315
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人