随笔分类 -  C++

拷贝控制和引用计数
摘要:#includeusing std::endl;using std::cin;using std::cout;#include using std::string;struct HasPtr_value{ //new 返回一个指向对象的指针 HasPtr_value(stri... 阅读全文

posted @ 2016-12-26 23:47 雪峰00 阅读(77) 评论(0) 推荐(0)

数组在表达式中解释为指针的规则受抑制的三种情况
摘要:总结来于《征服C指针》,前桥和弥#includeusing std::cin;using std::cout;using std::endl;int main(){ //..以下三种情况 数组在表达式中解释为指向其第一个元素的指针的规则受到抑制 int a... 阅读全文

posted @ 2016-12-13 22:49 雪峰00 阅读(109) 评论(0) 推荐(0)

征服c指针笔记
摘要:#includeusing std::cin;using std::cout;using std::endl;void Func_1(int i){ cout<<i<<endl;}int main(){ /*int a[3]; int *pa=a; int (*parray)... 阅读全文

posted @ 2016-09-17 10:49 雪峰00 阅读(102) 评论(0) 推荐(0)

c++可变长参数的函数
摘要:#include #include #include #include int tiny_sum(int i,...){ int j=i; va_list ap; va_start(ap,i);//将ap指向参数i后面的参数,也就是说第一个参数会被跳过。 whi... 阅读全文

posted @ 2016-09-11 15:28 雪峰00 阅读(617) 评论(0) 推荐(0)

优先队列(非模板函数,是int)
摘要:发现了一个可能是书里的错误,在swim函数中while检测的条件void priorityQueue::Swim(size_t t){ inArr[0]=inArr[t]; while (inArr[t/2]#ifndef LUPRIORITY_QUEUE#define ... 阅读全文

posted @ 2016-08-14 16:12 雪峰00 阅读(113) 评论(0) 推荐(0)

队列简要实现,是queue,不是dequeue
摘要:#ifndef MYQUEUE_H#define MYQUEUE_Hstruct Node{ int data; Node *next;};class LUqueue{public: LUqueue(); ~LUqueue(); void Push(int data); in... 阅读全文

posted @ 2016-07-24 21:09 雪峰00 阅读(143) 评论(0) 推荐(0)

栈实现,不是用template做的.
摘要:用单链表来实现栈,插入和删除的部分很有意思。写完这个感觉突然理解了书上说的适配器的观点,类就是这样,不管你底层实现是什么,表现成什么就好了,是一个黑盒。头文件Mystack.h#ifndef MYSATCK_H#define MYSTACK_Hstruct Node { in... 阅读全文

posted @ 2016-07-24 20:33 雪峰00 阅读(88) 评论(0) 推荐(0)

杨辉三角,一个vector实现,不复制,不用队列。
摘要:昨晚写到纸上,今天晚上调通,本来想要动态数组,但是发现这块的知识还欠缺,用着有问题。自己基础知识一直有问题,真是心急,要学习的知识好多,都不知道先学哪个。整个代码效率应该很低,因为进行了大量的判断。目前没有在网上搜到一样的代码,有点小虚荣。#include#include u... 阅读全文

posted @ 2016-07-13 23:22 雪峰00 阅读(146) 评论(0) 推荐(0)

多维数组与指针
摘要:今天在写遍历二维数组的时候,突然思考这个问题,原因在于作内层循环时,对指针和数组理解不到位。虽然一直都会也写遍历二维数组,但是原先从没有想过这个问题。(逃)头文件#ifndef TREBLE_H#define TREBLE_H#includetypedef int int_a... 阅读全文

posted @ 2016-06-09 18:17 雪峰00 阅读(128) 评论(0) 推荐(0)

三种方法检测数组边界
摘要:c++primer里的一道题int *a;int a[];int a[10];三种形参都一样,都被认为是int *a。能检测边界的只有这种 int(&a)[10]。#includeusing std::cin;using std::cout;using std::endl;i... 阅读全文

posted @ 2016-05-31 20:54 雪峰00 阅读(524) 评论(0) 推荐(0)

C++Primer习题6.12
摘要:编写一个小程序,从标准输入读入一系列 string 对象,寻找连续重复出现的单词。程序应该找出满足以下条件的单词的输入位置:该单词的后面紧跟着再次出现自己本身。跟踪重复次数最多的单词及其重复次数。输出重复次数的最大值,若没有单词重复则输出说明信息。例如,如果输入是:#incl... 阅读全文

posted @ 2016-05-31 16:44 雪峰00 阅读(96) 评论(0) 推荐(0)

《c++primer 》string *pstr = new string; *pstr = str;的疑问
摘要:题目:编写程序定义一个 vector 对象,其每个元素都是指向 string 类型的指针,读取该 vector 对象,输出每个 string 的内容及其相应的长度。疑问出在string *pstr = new string; *pstr = str;看了很多解答,汇总一下。#... 阅读全文

posted @ 2016-05-30 17:11 雪峰00 阅读(232) 评论(0) 推荐(0)

桶排序
摘要:#include#includeint MaxValue(std::vectorb);void BarrelSort(int c[], std::vectorb){ int max = MaxValue(b); int* a=new int [max+1]; for (int... 阅读全文

posted @ 2016-04-19 20:09 雪峰00 阅读(70) 评论(0) 推荐(0)

AVL树单选转和双旋转
摘要:看了好几天树了,也算有点心得。学树,必须要图。这里有两篇里的博客,在结合书,我用的是《数据结构与算法分析C++版》就可以了。http://blog.csdn.net/a454042522/article/details/8591421http://blog.csdn.net/... 阅读全文

posted @ 2016-04-02 14:07 雪峰00 阅读(329) 评论(0) 推荐(0)

C++指针理解《一》
摘要:贴个代码,注释比较清楚了。对于局部指针变量的问题,参见http://ask.csdn.net/questions/246619,感谢这么多热心人回答这个问题。#includeusing std::cin;using std::cout;using std::endl;cons... 阅读全文

posted @ 2016-04-02 13:36 雪峰00 阅读(84) 评论(0) 推荐(0)

C++中的函数指针与函数对象的总结(转载,作者佚名)
摘要:函数对象(msdn)https://msdn.microsoft.com/zh-CN/library/aa985932.aspx以下是对C++中的函数指针与函数对象的使用进行了详细的分析介绍,需要的朋友可以参考下篇一、函数指针函数指针:是指向函数的指针变量,在C编译时,每一个... 阅读全文

posted @ 2016-03-28 16:13 雪峰00 阅读(102) 评论(0) 推荐(0)

采用递归求数组里面求最大子序列的算法(手绘图解)
摘要:本文改编自我在知乎的回答。http://t.cn/RqPi9FO先上代码。private static int maxSumRec( int [ ] a, int left, int right ) { int maxLeftBorderSum = 0, ... 阅读全文

posted @ 2016-03-25 08:41 雪峰00 阅读(257) 评论(0) 推荐(0)

printdigit打印小数的一个问题,递归(问题)
摘要:用递归打印小数,主要问题在于寻找小数的位数,首先解决小数和整数的分离;其次是小数的位数。1.小数和整数的分离:int num;double dic;num = int(n);dic = n - num;n是传进的double形参,num用强制转换获得整数部分,dic是获得小数... 阅读全文

posted @ 2016-03-24 11:31 雪峰00 阅读(461) 评论(0) 推荐(0)

在数组中选择k
摘要:不得不说auto关键字真的很好用#include#includeusing std::vector;using std::cin;using std::cout;using std::endl;class SelsctK{private: vector arr; int f... 阅读全文

posted @ 2016-03-23 20:29 雪峰00 阅读(82) 评论(0) 推荐(0)

《21天学通C++》读书笔记,名字很奇怪,但写的还蛮好,
摘要:变量长度指的是:程序员声明变量时,编译器将预留多少内存,用于存储赋给该变量的数据。变量的长度随类型而异,C++提供了一个方便的运算符——sizeof,可用于确定变量的长度(单位为字节)或类型。在有些情况下,根据赋给变量的初值,很容易知道其类型。例如,如果将变量的初值设置成了 ... 阅读全文

posted @ 2016-03-23 10:42 雪峰00 阅读(155) 评论(0) 推荐(0)

导航