12 2012 档案
摘要:使用递归:#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
阅读全文
摘要:#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
阅读全文
摘要:头文件:#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...
阅读全文
摘要:最大的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+
阅读全文
摘要:1.函数对象和STL函数对象链接:http://www.cnblogs.com/cobbliu/archive/2012/04/21/2461184.html2.成员函数查找C++必知必会——条款24。3.禁止复制和制造抽象基类C++必知必会——条款32,33。
阅读全文
摘要:方法一为用于本题的方法,方法二为通用方法,即将数组分为两部分,两部分性质不相同。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;...
阅读全文