
c++
piyongze
这个作者很懒,什么都没留下…
展开
-
unicode编码简单剖析
或许你还在为不能理解unicode和utf8而困惑,那么今天我就简单讲解下。 我们都知道ASCII码,对于退格,其符号表示是'\b',这里我们称之为符号编码,其数值编码则对应8。下文的符号编码和数值编码与此处相同。 而unicode和utf8也是这样,unicode使用一组'\u'+数组的形式,来表示符号编码,而utf8你可以理解为对应的一种数值编码,和ASCI原创 2013-12-05 10:23:02 · 887 阅读 · 0 评论 -
输出链表倒数第k个元素
原题:输出链表倒数第k个元素考点:代码鲁棒性(考虑函数定义域)代码:#include"linklist.h"pnode searchk(pnode head,unsigned int k){if(head==NULL||k==0) return NULL;pnode p=head;pnode q=NULL;for(unsigned int i=0;i<k-1;++i){原创 2014-04-14 17:29:52 · 1071 阅读 · 0 评论 -
反转链表
题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。要点:边界测试代码:#include "linklist.h"pnode rvslist(pnode head){pnode rhead=NULL;pnode node=head;pnode pre=NULL;while(node!=NULL){pnode next=node->next;i原创 2014-04-14 20:54:10 · 935 阅读 · 0 评论 -
指针系列实例头文件
说明:本文件为博客所有指针系列代码共用头文件命名:linklist.h代码:#ifndef linklist_h_#define linklist_h_#includetypedef struct lnode{int value;lnode* next;} node,*pnode;pnode head;void crtlist(){int i;head=new原创 2014-04-14 17:25:01 · 3085 阅读 · 0 评论 -
合并两个排序的链表
题目:输入两个递增排序的链表,合并这两个链表。思路:使用递归#include"linklist.h"pnode merge(pnode head1,pnode head2){if(head1==NULL) return head2;else if(head2==NULL) return head1;pnode mernode=NULL;if((head1->value)valu原创 2014-04-14 22:40:26 · 742 阅读 · 0 评论 -
cin总结
代码:* Return.cpp * * Created on: 2014年4月17日 * Author: root */#include#include#includeusing namespace std;vector lists;int main(){ string str; int sel; bool quit=false; for(int i=原创 2014-04-17 16:53:23 · 909 阅读 · 0 评论 -
教你以gcc的方式使用Visual Studio 2013 tool
如果你是一个命令行控,如果你习惯了g+原创 2014-04-10 16:45:16 · 4151 阅读 · 0 评论 -
两个队列模拟栈
#include#includeusing namespace std;templateclass CStack{public:CStack(){};~CStack(){};void append(const T& node);T deleteHead();private:queue queue1,queue2;};templatevoid CStack::appen原创 2014-04-11 11:36:25 · 702 阅读 · 0 评论 -
c++实现快速排序
#includeusing namespace std;void swap(int* a,int* b);void qksort(int data[],int length){if(length==0) return;int i=0,j=length-1,key=data[0];while(i!=j){while(data[j]>key&&j>0) j--;swap(&data原创 2014-04-11 14:41:03 · 792 阅读 · 0 评论 -
旋转数组的最小数字(改进版算法)
#includeusing namespace std;//directly sort if the array has repeat valueint drctsort(int a[],int length){int resu=a[0],i;for(i=0;i<length;i++)if(a[i]<resu) resu=a[i];return resu;}//core alg原创 2014-04-11 15:48:16 · 823 阅读 · 0 评论 -
二进制中1的个数
题目:请实现一个函数,输入一个整数,输出该数二进制表示中1的个数。思路:运用”位运算“代码:#includeusing namespace std;int NumberOf1(int n){int count=0;unsigned int flag=1;while(flag){if(n&flag)count++;flag=flag<<1;}return coun原创 2014-04-14 10:12:25 · 822 阅读 · 0 评论 -
调整数组顺序使奇数位于偶数前面
题目:调整数组顺序使奇数位于偶数前面思路:快排缩略算法 注意提高可扩展性代码:#includeusing namespace std;void Reorder(int *pData,unsigned int length,bool (*func)(int)){if(pData==NULL||length==0) return;int *pBegin=pData;int *p原创 2014-04-14 16:04:11 · 676 阅读 · 0 评论 -
在O(1)时间删除链表节点
题目:给定单向链表的头指针和一个节点指针,定义一个函数在O(1)时间删除该节点。思路:题目要求的时间复杂度,迫使我们不得不,开拓思维,另辟蹊径。代码:#includeusing namespace std;typedef struct ListNode{int value;ListNode* next;} lnode,*plnode;plnode head;plnode原创 2014-04-14 15:43:01 · 1109 阅读 · 0 评论 -
打印1到最大的n位数
题目:打印1到最大的n位数考点:怎样避免使用基本类型的溢出 怎样使用字符串模拟数字代码:#includeusing namespace std;bool Increment(char* number);void PrintNumber(char* number);void printToMaxOfNDigits(int n){if(n<0) return;char *numb原创 2014-04-14 14:33:13 · 851 阅读 · 0 评论 -
C++ const总结
const是代码中的常客。Today,我就略加总结。 主要通过几段代码讲解,Code sec1:#includeint funa(const int& a){printf("%d\n",a);}int funb(int& a){printf("%d\n",a);}int func(int a){printf("%d\n",a);}int fund原创 2014-01-21 17:56:16 · 629 阅读 · 0 评论 -
C++栈内存分配剖析
Environment:gccCode sec1:int main(){int a=3;int b=3;int c=3;double d=6.0;int f=4;printf("%d\n",sizeof(double));printf("%d\n",&a);printf("%d\n",&b);printf("%d\n",&c);printf("%d\n",&d);p原创 2014-01-22 11:39:12 · 723 阅读 · 0 评论 -
C++复制构造函数、赋值运算符以及等于运算符
A b; (1)A a=b; (2)当我们执行上述(2)时,复制构造函数执行,因为此时,需要构造对象;A c; (3)c=a; (4)当我们执行(4)时,重载的赋值运算符就会起作用了。if(a==b) (5)当我们执行语句(5)时,如果我们还未重载==运算符,编译器则报错。总结:复制构造函数和赋值运算符,前者构造对象时执原创 2014-01-22 17:45:36 · 884 阅读 · 0 评论 -
C++构造函数中的初始化
Code sec1:TableTennisPlayer::TableTennisPlayer(const string& fn, const string& ln, bool ht) :firstname(fn), lastname(ln), hasTable(ht){}Code sec2:TableTennisPlayer(const string &fn,const st原创 2014-01-23 09:44:14 · 870 阅读 · 0 评论 -
strlen和strcpy_s引发的堆破坏
Code sec1:int main(){ char cp[] = "hello"; char *c = new char[strlen(cp) + 1]; cout << strlen(c) << endl; printf("%02X\n", c); strcpy_s(c,strlen(c),cp); delete[] c; cout << c << endl;}Resul原创 2014-01-24 12:19:30 · 1284 阅读 · 0 评论 -
vs2013错误总结
Code sec1:RatedPlayer(unsigned int r=0, const TableTennisPlayer &ttp);错误说明:missing default parameter for parameter 2结论:默认值必须自右向左设置原创 2014-01-23 10:34:37 · 921 阅读 · 0 评论 -
对数组使用sizeof,能否得到正确答案呢?
Code sec:#includeint GetSize(int data[]){return sizeof(data);}int main(){int data1[]={1,2,3,4,5};int size1=sizeof(data1);int* data2=data1;int size2=sizeof(data2);int size3=GetSize(data1原创 2014-01-26 15:16:12 · 1372 阅读 · 0 评论 -
一道题目的二种思路,你学到了什么?
面试中,面试官经常会考察的要点,就是应试者的思路。而本文,介绍了笔者看到这个面试题后的思路,以及书本给出的更好的思路的比较,给出简要分析和总结。题目:在一个二维数组中,每一行从左到右递增排列,每一类自上而下递增排列。请完成函数,完成数组中特定数的查找,判断数组中是否存在该整数。本人解法:#includeusing namespace std;enum{ ROW = 4, COL =原创 2014-01-26 16:27:34 · 961 阅读 · 0 评论 -
Visual Studio2013 C++使用API连接MYSQL(64位)
环境:mysql5.6.12(x64) 、visual studio 2013 语言:C++ 步骤: 1.创建win32应用程序 2.添加include目录(%MYSQL_HOME%/include)(注:%MYSQL_HOME%替换为你的mysql安装目录) 3.cop原创 2014-02-19 13:49:29 · 1941 阅读 · 0 评论 -
青蛙跳台阶问题
题目:一只青蛙一次可以跳上1级台阶,也可以跳上2级台阶,求该青蛙跳上一个n级台阶总共有多少中跳法。思路:问题本质上是fibonacci问题。代码:#includeusing namespace std;int qwfibon(int n){if(n<1) throw "param error";if(n==1) return 1;if(n==2) return 2;if(原创 2014-04-14 09:35:45 · 1497 阅读 · 0 评论 -
数值的整数次方
题目:实现函数double Power(double base,int exponent),求base的exponent次方。要点:定义域解析、错误处理、效率代码:#includeusing namespace std;bool g_InvalidInput=false;double powerWithUnsignedExponent(double base,unsigned i原创 2014-04-14 11:05:45 · 816 阅读 · 0 评论