上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页
摘要: #include<iostream>using namespace std;struct BTreeNode{ int data; struct BTreeNode *lchild,*rchild;};void PostOrder(BTreeNode *bt) { if(bt!=NULL) { PostOrder(bt->lchild); PostOrder(bt->rchild); printf("%d\n",bt->data); } } void PreInCreate(BTreeNode *&root,int pre... 阅读全文
posted @ 2013-01-02 19:11 代码改变未来 阅读(225) 评论(0) 推荐(0) 编辑
摘要: 使用递归:#include<iostream>using namespace std;struct ListNode{ int value; ListNode *next;};void Print(ListNode *list){ if(list!=NULL) { if(list->next!=NULL) Print(list->next); cout<<list->value<<endl; } }int main(){ int n; while(cin>>n) { ListNode *head=(ListNode*)mallo 阅读全文
posted @ 2012-12-29 22:40 代码改变未来 阅读(197) 评论(0) 推荐(0) 编辑
摘要: #include<iostream>#include<string>using namespace std;void ReplaceBlank(char *str,int length){if(str==NULL&&length<0)return;int i=0;int j=0;for(i=0;str[i]!='\0';i++){if(str[i]==' ')j++;}int newlength=i+2*j;if(newlength>=length)return;int l=i-1;for(int k=newl 阅读全文
posted @ 2012-12-29 19:10 代码改变未来 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 头文件:#include <stdio.h>struct BinaryTreeNode { int m_nValue; BinaryTreeNode* m_pLeft; BinaryTreeNode* m_pRight; };先序输入建立:void Create_BT(BinaryTreeNode *&bt)//先序输入二叉树{ int d; scanf("%d",&d); if(d==-1)bt=NULL; else { bt=(BinaryTreeNode*)malloc(sizeof(Binar... 阅读全文
posted @ 2012-12-16 16:22 代码改变未来 阅读(386) 评论(0) 推荐(0) 编辑
摘要: 最大的K个数堆排序可运行代码:已通过测试:#include<iostream>using namespace std;void heapadjust(int a[],int i,int n);void build_min_heap(int a[],int n)//n为heap元素个数{ int i; for(i=n/2-1;i>=0;i--)//非叶节点最大序号为n/2-1 { heapadjust(a,i,n);//调整堆 }}void heapadjust(int a[],int i,int n)//最小堆调整{ int temp=a[i]; for(int j=2*i+ 阅读全文
posted @ 2012-12-12 23:52 代码改变未来 阅读(235) 评论(0) 推荐(0) 编辑
摘要: 1.函数对象和STL函数对象链接:http://www.cnblogs.com/cobbliu/archive/2012/04/21/2461184.html2.成员函数查找C++必知必会——条款24。3.禁止复制和制造抽象基类C++必知必会——条款32,33。 阅读全文
posted @ 2012-12-03 20:27 代码改变未来 阅读(105) 评论(0) 推荐(0) 编辑
摘要: 方法一为用于本题的方法,方法二为通用方法,即将数组分为两部分,两部分性质不相同。void Reorder(int *pData, unsigned int length, bool (*func)(int));bool isEven(int n);// ====================方法一====================void ReorderOddEven_1(int *pData, unsigned int length){ if(pData == NULL || length == 0) return; int *pBegin = pData;... 阅读全文
posted @ 2012-12-01 22:42 代码改变未来 阅读(292) 评论(0) 推荐(0) 编辑
摘要: 1.问题描述快速找出发帖超过一半的的ID问题变型:现在有一个数组,已知一个数出现的次数超过了一半,请用最小的复杂度的算法找出这个数。问题扩展:有三个发帖很多的ID,他们的发帖数目超过了帖子总数目的1/4,请从发帖ID列表中找出它们2.分析与解法每次从列表中删除两个不同的ID,那么剩下的ID列表中,“水王”的ID出现次数仍然超过剩余数目的一半,因此每次删除两个不同的ID,直到剩下的所有ID都相同,那么剩下的就是水王的ID。我们可以设置一个candidate和一个计数器nTimes,candidate为ID列表第一个ID,nTimes初始值为0,遍历整个ID列表,当遍历的ID与candidate相 阅读全文
posted @ 2012-11-29 23:46 代码改变未来 阅读(1179) 评论(0) 推荐(0) 编辑
摘要: C++字符串库函数——strcat,strcmp,strlen,itoa#include<iostream>#include<assert.h> using namespace std;char *strcat(char * strDest,const char *strSrc){ char *address=strDest; assert((strDest!=NULL)&&(strSrc!=NULL)); while(*strDest) strDest++; while(*strDest++=*strSrc++) { NULL; } return ad 阅读全文
posted @ 2012-11-26 21:44 代码改变未来 阅读(1062) 评论(0) 推荐(0) 编辑
摘要: 何海涛第49题。程序员面试100题第20题题目:输入一个表示整数的字符串,把该字符串转换成整数并输出。例如输入字符串"345",则输出整数345。-----------------------------此题一点也不简单。不信,你就先不看一下的代码,你自己先写一份,然后再对比一下,便知道了。1.转换的思路:每扫描到一个字符,我们把在之前得到的数字乘以10再加上当前字符表示的数字。这个思路用循环不难实现。2.由于整数可能不仅仅之含有数字,还有可能以'+'或者'-'开头,表示整数的正负。如果第一个字符是'+'号,则不需要做任何操作 阅读全文
posted @ 2012-11-24 23:51 代码改变未来 阅读(1013) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 16 下一页