qingcheng奕  

2013年11月21日

摘要: //二t叉?搜?索??树???的??搜?索??#include #include typedef int KeyType;typedef struct node{ KeyType key; struct node *lchild,*rchild;}BSTNode;int Compare(int index1,int index2){ if(index1>index2) return 1; if(index1... 阅读全文
posted @ 2013-11-21 16:39 qingcheng奕 阅读(183) 评论(0) 推荐(0) 编辑
 
摘要: #include using namespace std;void move_disk(char src,char dst){ cout">disks; towers(disks, 'A','B' ,'C'); return 0;}//物?品??重?量??S,??共2n件t物?品??,??从???其?中D选?出?若??干??件t放??在??背?3包???里??,??使?1得??重?量??之?和??为as#includeusing namespace std;int W[10];bool Knap(int... 阅读全文
posted @ 2013-11-21 16:38 qingcheng奕 阅读(121) 评论(0) 推荐(0) 编辑
 
摘要: //单???链???表???#include using namespace std;typedef char datatype;typedef struct node{ datatype data; struct node* next;}listnode;typedef listnode* linklist;listnode *p;//建??立???链???表???linklist createlist(){ linklist head = (listnode*)malloc( sizeof(list... 阅读全文
posted @ 2013-11-21 16:35 qingcheng奕 阅读(475) 评论(0) 推荐(0) 编辑
 
摘要: //中D序??遍???历???二t叉?树???//先??序??遍???历???二t叉?树???//后??序??遍???历???二t叉?树???#include using namespace std;typedef char DataType;struct BiNode{ DataType data; struct BiNode *lchild,*rchild;};void inOrder(BiNode *p){ if(p!=NULL) { ... 阅读全文
posted @ 2013-11-21 16:33 qingcheng奕 阅读(339) 评论(0) 推荐(0) 编辑
 
摘要: SeqQueue.h#define QueueSize 100typedef char DataType;class SeqQueue{public: DataType data[QueueSize]; int front; int rear; void Initial(); bool IsEmpty(); bool IsFull(); void EnQueue(DataTy... 阅读全文
posted @ 2013-11-21 16:30 qingcheng奕 阅读(263) 评论(0) 推荐(0) 编辑
 
摘要: #define StackSize 100typedef char DataType;class stack{public: DataType data[StackSize]; int top; void Initial(); bool IsEmpty(); bool IsFull(); void Push(DataType x); DataTy... 阅读全文
posted @ 2013-11-21 16:27 qingcheng奕 阅读(417) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/将一个升序的数组转换成height balanced BST高度平衡的二叉搜索树,根据二叉搜索树的特征,所有比根节点小的值,都在根节点的左边,所有比根节点大的值,都在根节点的右边。建立的过程就是一个个的插入。但要求是高度平衡的,即不能是各种偏的那样,否则的话,搜索的代价会增大,最佳的时候是O(height),height balanced的时候也是O(height).所以会涉及到各种左旋转,右旋转,先左旋再右旋,先右旋再左旋的操作(为了平衡高度) 阅读全文
posted @ 2013-11-21 16:04 qingcheng奕 阅读(209) 评论(0) 推荐(0) 编辑

2013年11月16日

摘要: http://oj.leetcode.com/problems/plus-one/进位加法#include #include using namespace std;class Solution {public: vector plusOne(vector &digits) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. vector ansV... 阅读全文
posted @ 2013-11-16 15:43 qingcheng奕 阅读(147) 评论(0) 推荐(0) 编辑

2013年11月15日

摘要: http://oj.leetcode.com/problems/pascals-triangle-ii/杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algorithm to use onlyO(k) extra space?其实计算当前行,也只用到前一行了。再前面的没有用。class Solution {public: vector getRow(int rowIndex) { // IMPORTANT: Please reset any member data you declared, as // the same... 阅读全文
posted @ 2013-11-15 14:51 qingcheng奕 阅读(142) 评论(0) 推荐(0) 编辑
 
摘要: http://oj.leetcode.com/problems/pascals-triangle/杨辉三角先分析数据,找出规律ans[row][col] = ans[row-1][col-1]+ans[row-1][col]#include #include #include using namespace std;class Solution {public: vector > generate(int numRows) { // IMPORTANT: Please reset any member data you declared, as // the ... 阅读全文
posted @ 2013-11-15 14:01 qingcheng奕 阅读(155) 评论(0) 推荐(0) 编辑