该文被密码保护。 阅读全文
posted @ 2012-12-04 23:22 曙光_用代码记录人生 阅读(3) 评论(0) 推荐(0) 编辑
摘要: #include <iostream>using namespace std;typedef struct node{ int value; struct node* next; node(){next=NULL;} node(int v,node* n){value=v;next=n;}}node;void insert(node*& head,int a[],int n)//??????????????????注意要用引用{ node* rear=NULL; for(int i=0;i<n;i++) { if(!head) rear=head=new node(a 阅读全文
posted @ 2012-12-04 23:01 曙光_用代码记录人生 阅读(202) 评论(0) 推荐(0) 编辑
摘要: 1.O(n)的排序(其实是快速排序的第一步):把一个数组的排序,前面是奇数,后面是偶数,时间复杂度O(n),空间复杂度O(1)#include <iostream>#define arraylength 10using namespace std;int array[arraylength]={1,3,3,3,5,11,15,13,17,15};void rearrangeArray(int array[],int n)//前面是奇数后面是偶数{ int front=-1; int rear=n; while(front<rear) { while(fro... 阅读全文
posted @ 2012-12-04 21:47 曙光_用代码记录人生 阅读(394) 评论(0) 推荐(0) 编辑
摘要: 二叉树问题总可以用几种方法解决:递归的方法,基本上第一眼就是要用递归 2.几种遍历,前序、中序、后序、 层次遍历(重,还可以用来求最大宽度,)void levelTraverse(BTNode*root)//还可以求最大宽度,{ vector<BTNode*>v; int front=0,rear; if(root) v.push_back(root); int maxWidth=0; while(front<v.size()) { rear=v.size(); int tempMax=0; while(f... 阅读全文
posted @ 2012-12-04 21:27 曙光_用代码记录人生 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 【转载 xwdreamer】1.把二元查找树转变成排序的双向链表题目:输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表。要求不能创建任何新的结点,只调整指针的指向。 10 / \ 6 14/ \ / \4 8 12 16转换成双向链表4=6=8=10=12=14=16。首先我们定义的二元查找树 节点的数据结构如下:struct BSTreeNode{ int m_nValue; // value of node BSTreeNode *m_pLeft; // left child of node BSTreeNode *m_pRight; // right child of node 阅读全文
posted @ 2012-12-04 21:01 曙光_用代码记录人生 阅读(302) 评论(0) 推荐(0) 编辑