04 2015 档案
摘要:class AES { public: AES(){m_data=2;} virtual void fun1(){coutfun1(); //对象未构造,虚表未产生;编译通过,运行失败; p->fun2(); p->fun3(); //对象未构造,成员变量未产生;编译通过,运行失败; re...
阅读全文
posted @ 2015-04-22 22:04
hy1hy
摘要:1. 纯虚类特点 纯虚类不能实例化;class AES{public: virtual ~AES()=0;};AES::~AES(){} class BES:public AES{public: virtual ~AES()=0;};int main(){ AES *p=new BES; ...
阅读全文
posted @ 2015-04-22 21:56
hy1hy
摘要:1. 找出下列代码的错误void test(){ char string[10]; char *str="0123456789"; strcpy(string,str);}字符串str需要11个字节才能存放下(包括末尾的'\0'),而string只有10个字节的空间;strcpy会导致数组越界...
阅读全文
posted @ 2015-04-22 21:50
hy1hy
摘要:1. 产生死锁的原因主要是:(1) 因为系统资源不足。(2) 进程运行推进的顺序不合适。(3) 资源分配不当等。2. 线程死锁产生的必要条件:(1)互斥条件:一个资源每次只能被一个进程使用。(资源固有属性,无法破坏)(2)请求与保持条件:一个进程因请求资源而阻塞时,对已获得的资源保持不放。(一次性将...
阅读全文
posted @ 2015-04-19 22:34
hy1hy
摘要:1. 关于group by 日期 结果2005-05-09 胜2005-05-09 胜2005-05-09 负2005-05-09 负2005-05-10 胜2005-05-10 负2005-05-10 负 日期 胜 负2005-05-09 2 ...
阅读全文
posted @ 2015-04-19 22:13
hy1hy
摘要:1. 字符串转换为十进制整数;字符串形式为" -1234";2. 实现int itoa(char *str){ int nRet=0; bool minus=false; if(NULL==str) return nRet; //空格判断 while(' '==*str) ...
阅读全文
posted @ 2015-04-18 17:13
hy1hy
摘要:1. 数组形式如下a[3][3]={11, 2, 3 10, 8, 9 5, 7, 6};输出形式如下: 3,2,9,11,8,6,10,7,52. 实现void printf_test(){ int istart=0; int jstart=n-1; //该处的n=3 for(in...
阅读全文
posted @ 2015-04-18 17:06
hy1hy
摘要:1. 实现bool find_common(int a[], int len1, int b[], int len2){ int i=0; int j=0; while(ib[j]) j++; } return false;}
阅读全文
posted @ 2015-04-18 16:56
hy1hy
摘要:有一对兔子,过一个月之后长成大兔子,到第三个月就可以生下一对兔子并且以后每个月都生下一对兔子,而所生的一对小兔子也同样到一个月之后长成大兔子,到第三个月就可以生下一对小兔并且以后每个月都会生一对。假设所有兔子一年内均不死亡,问一年后共有几对兔子?兔子的对数,就是Fibonacci数列#include...
阅读全文
posted @ 2015-04-18 16:53
hy1hy
摘要:1.非递归实现(两个数相乘再除以最大公约数)int max_common_doulbe(int a, int b){ int nMax=a>b?a:b; int nMin=ab?a:b; int nMin=a<b?a:b; int nMaxGY=nMax; //最大公约数 if(...
阅读全文
posted @ 2015-04-18 16:26
hy1hy
摘要:1. 非递归实现int max_common_divisor(int a, int b){ int nRet=1; int max=a>b?b:a; for(int i=min; i>2; i++) { if(a%i==0 && b%i==0) nRet=i; } return n...
阅读全文
posted @ 2015-04-18 15:52
hy1hy
摘要:#include using namespace std;class stream{public: stream(){cout<<"stream constructer"<<endl; ~stream(){cout<<"stream destructer"<<endl;};class iistr...
阅读全文
posted @ 2015-04-18 11:18
hy1hy
摘要:临时对象(无法作为左值,即对象类型为const类型)产生的时期:1. 以值的方式给函数传参;2. 类型转换;3. 函数返回一个对象时;使用:string foo();void bar(string& s);bar(foo()); //编译错误bar("hello world"); //...
阅读全文
posted @ 2015-04-18 10:51
hy1hy
摘要:void main(){ int a[5]={1,2,3,4,5}; int *ptr1=(int*)(&a+1); int *ptr2=(int*)((int)a+1); int *ptr3=(int*)(a+1); int *ptr4=a; //假设数组a的开始地址为0x1000...
阅读全文
posted @ 2015-04-18 10:28
hy1hy
摘要:1. union的长度union{ int k; int p[4]; double q;}data;sizeof(data)=20; //结构体中最大的数据长度2.struct的长度struct{ int k; double q;}data;sizeof(data)=16; //结...
阅读全文
posted @ 2015-04-18 10:23
hy1hy
摘要:1.返回两个数中的最小值#define MIN(x,y) ( (x)>(y) ? (y) : (x) )2.求数组的元素个数#define NTBL (sizeof(table)/sizeof(table[0])
阅读全文
posted @ 2015-04-18 10:06
hy1hy
摘要:C中的struct与C++中的struct的区别:1. C中struct只能定义变量,不能定义函数;C++中的struct可以定义变量和函数;2. struct中默认的访问权限为public;而class中默认的访问权限为private;3. class可用于表示模板类型。
阅读全文
posted @ 2015-04-18 09:59
hy1hy
摘要:输出格式1.%b --- 二进制2.%d --- 十进制3.%u --- 无符号整数4.%x --- 十六进制5.%o --- 八进制6.%s --- 字符串使用1:void printf_use_one(){ char a=128; printf("%d", a); //输出结果为-12...
阅读全文
posted @ 2015-04-18 09:55
hy1hy
摘要:static的作用:1.在函数体内,一个被声明为static的变量在这一函数调用过程中维持其值不变(上一次使用的值)、设置存储域;2.在模块内(函数体外),static变量可以被模块内的所有函数访问;但不可以被模块外的函数访问、设置作用域;3.在模块内,static函数可以被模块内的所有函数调用;但...
阅读全文
posted @ 2015-04-18 09:02
hy1hy
摘要:const的作用:1.阻止一个变量被改变;通常在定义时,需要对变量进行初始化。2.对指针来说,可以指定指针本身为const;也可以指定指针指向的数据为const。3.在一个函数声明中,修饰形参;表明在函数内部不能修改改变其值。4.对类成员函数,指定为const类型;表明该函数为常函数,不能修改类成员...
阅读全文
posted @ 2015-04-18 08:44
hy1hy
摘要:一、C、C++程序编译时内存分为5大存储区:堆区、栈区、静态区(全局区)、文字常量区(储存字符串常量)、程序代码区(存放二进制程序)(1)静态存储区域: 静态存储区域的内存在程序编译时就已经分配好,这块内存在程序的整个运行期间都存在。速度快、不容易出错,因为有系统会善后。例如全局变量,static...
阅读全文
posted @ 2015-04-16 22:25
hy1hy
摘要:1.迭代器类型· Input iterators(输入) 提供对数据的只读访问。· Output iterators(输出) 提供对数据的只写访问。· Forward iterators(正向) 提供读写操作,并能向前推进迭代器。· Bidirectional iterators(全向) 提供读写操...
阅读全文
posted @ 2015-04-16 22:11
hy1hy
摘要:排序(Heapsort)是指利用堆积树(堆)这种数据结构所设计的一种排序算法,它是选择排序的一种。可以利用数组的特点快速定位指定索引的元素。堆分为大根堆和小根堆,是完全二叉树。大根堆的要求是每个节点的值都不大于其父节点的值,即A[PARENT[i]] >= A[i]。在数组的非降序排序中,需要使用的...
阅读全文
posted @ 2015-04-16 19:37
hy1hy
摘要:快速排序(Quicksort)是对冒泡排序的一种改进。它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别进行快速排序,整个排序过程可以递归进行,以此达到整个数据变成有序序列。int quickSort(i...
阅读全文
posted @ 2015-04-16 19:11
hy1hy
摘要:冒泡排序算法的运作如下:比较相邻的元素。如果第一个比第二个大,就交换他们两个。对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。在这一点,最后的元素应该会是最大的数。针对所有的元素重复以上的步骤,除了最后一个。持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。void ...
阅读全文
posted @ 2015-04-16 18:44
hy1hy
摘要:void insertSort(){ int a[10]={10,2,3,5,8,9,7,1,55,6}; int nVal=0; for(int i=1; i=0&&nVal=low&&nVal=high+1&&nVal<a[j] ) { a[j+1]=a[j]; ...
阅读全文
posted @ 2015-04-16 18:32
hy1hy
摘要:后序遍历按照“左孩子-右孩子-根结点”的顺序进行访问。1.递归实现void postOrder(BinTree* root){ if(root!=NULL) { inOrder(root->lchild); inOrder(root->rchild); coutdata; }...
阅读全文
posted @ 2015-04-16 17:54
hy1hy
摘要:中序遍历按照“左孩子-根结点-右孩子”的顺序进行访问。1.递归实现void inOrder(BinTree* root){ if(root!=NULL) { inOrder(root->lchild); coutdata; inOrder(root->rchild); }}2...
阅读全文
posted @ 2015-04-16 17:45
hy1hy
摘要:前序遍历按照“根结点-左孩子-右孩子”的顺序进行访问。1.递归实现void preOrder(BinTree* root){ if(root!=NULL) { coutdata; preOrder(root->lchild); preOrder(root->rchild); ...
阅读全文
posted @ 2015-04-16 17:39
hy1hy
摘要:templateclass QStack{public: QStack(){} ~QStack(){} void push(T const &); T pop();private: Queue Q1,Q2;};templatevoid QStack::push(T const &e){ //入...
阅读全文
posted @ 2015-04-16 17:08
hy1hy
摘要:templatestruct MyQueue{ void push(T &t) { s1.push(t); } T front() { if(s2.empty()) { if(s1.size() == 0) throw; while(!s1.empty...
阅读全文
posted @ 2015-04-16 16:39
hy1hy
摘要:1.已知n个人(n>=1)围坐一圆桌周围,从1开始顺序编号。从序号为1的人开始报数,顺时针数到m的那个人出列。他的下一个人又从1开始报数,数到m的那个人又出列。依此规则重复下去,直到所有人全部出列。请问最后一个出列的人的编号。Node* RemoveList(Node* head, int len)...
阅读全文
posted @ 2015-04-16 16:15
hy1hy
摘要:1.代码实现如下node* bubble(node* head, int len){ int nVal = 0; node* pCur=NULL; node* pNext=NULL; //外部循环为len for(int i=0; inext; //内部循环逐次减少 for...
阅读全文
posted @ 2015-04-16 03:03
hy1hy
摘要:解决方案:设立两个指针,一个单步走,一个两步走,当大步指针到达链表尾部的时候,小步指针也正好位于链表中间位置。
阅读全文
posted @ 2015-04-16 02:34
hy1hy
摘要:解决方案:初始两个节点指针Node* p1;Node* p2;p1先遍历K个节点;然后p1和p2同时开始遍历;当p1为NULL时,p2指向的节点即为倒数第K个节点。
阅读全文
posted @ 2015-04-16 02:32
hy1hy
摘要:解决方案:把p所指节点的下一个节点的值赋值给p所指的节点,因此就就可以通过删除p指向的下一个节点。
阅读全文
posted @ 2015-04-16 02:26
hy1hy
摘要:1.两个链表都带有头结点Node* Merge(Node* head1, Node* head2){ if(head1==NULL || head1->next==NULL) return head2; if(head2==NULL || head2->next==NULL) ret...
阅读全文
posted @ 2015-04-16 02:17
hy1hy
摘要:1.辅助指针void ReverseList(LinkList* ListHead){ if(NULL==ListHead || NULL==ListHead->next) return; LinkList* pPre=ListHead; LinkList* pCur=ListHead-...
阅读全文
posted @ 2015-04-15 22:53
hy1hy
摘要:解决方案:1.找出链表1的环入口节点a1,链表2的环入口节点a2;2.如果a1=a2; 说明两个链表可能在入环之前或者入环第一个节点相交;将a1,a2作为两个链表的最后一个节点,转化为不带环的链表相交;其实在这种情况下已经说明两个链表已经相交了。3.如果a1!=a2;以a1为基准节点进行while循...
阅读全文
posted @ 2015-04-15 22:22
hy1hy
摘要:1---2---3 ---4---5---6---711---12---链表1:1---2---3---4---5---6---7链表2:11---12---4---5---6---7解决方案:1.直接将链表1中的节点与链表2中的节点进行比较;如果存在相同的则相交。缺点:效率慢。2.将链表1建...
阅读全文
posted @ 2015-04-15 21:53
hy1hy
摘要:1.第一种实现bool List_is_loop(slist *head){ slist *slow=head; slist *fast=head; while(NULL!=fast && NULL!=fast->next) { slow=slow->next; fast=fas...
阅读全文
posted @ 2015-04-15 21:16
hy1hy
摘要:int b[2]={2,3}; int c[2]={4,5}; int **p,**q,**m; q=new int*[2]; q[0]=new int; q[1]=new int; **q=c[0]; *(*q+1)=c[1]; delete q[0]; delete q[1]; dele...
阅读全文
posted @ 2015-04-11 19:47
hy1hy
摘要:1. 默认成员函数Class Empty{ public: Empty(); // 缺省构造函数 Empty( const Empty& ); // 拷贝构造函数 ~Empty(); // 析构函数 Empty& operator=( const Empty& ); // 赋值运算符 Empty* ...
阅读全文
posted @ 2015-04-11 17:40
hy1hy

浙公网安备 33010602011771号