随笔分类 -  C++

C++编译原理
摘要:C++ 》cpp 》预编译(加头文件) 》编译 》obj 》链接器 》可执行文件 几个概念: 1、编译:编译器对源文件进行编译,就是把源文件中的文本形式存在的源代码翻译成机器语言形式的目标文件的过程,在这个过程中,编译器会进行一系列的语法检查。如果编译通过,就会把对应的CPP转换成OBJ文件。 2、 阅读全文

posted @ 2018-03-27 01:21 flyingwaters 阅读(3540) 评论(0) 推荐(1)

extern,以及在linux头文件中的应用
摘要:引用一个定义在其它模块的全局变量或函数(如,全局函数或变量定义在A模块,B欲引用)有两种方法,一、B模块中include模块A的头文件。二、模块B中对欲引用的模块A的变量或函数重新声明一遍,并前加extern关键字。 声明外部变量 现代编译器一般采用按文件编译的方式,因此在编译时,各个文件中定义的全 阅读全文

posted @ 2018-03-27 01:11 flyingwaters 阅读(1095) 评论(0) 推荐(0)

iostream源码
摘要:// Standard iostream objects -*- C++ -*- // Copyright (C) 1997-2015 Free Software Foundation, Inc.//// This file is part of the GNU ISO C++ Library. T 阅读全文

posted @ 2018-03-27 00:57 flyingwaters 阅读(1040) 评论(0) 推荐(0)

一道简单的题我犯的傻逼错误
摘要:#include<iostream>#include<string>#include<algorithm>using namespace std;int main(){ int k; string h=""; cin>>k; while(k!=0){ if(k%2==0){k=(k-2)/2; h. 阅读全文

posted @ 2018-02-26 15:45 flyingwaters 阅读(138) 评论(0) 推荐(0)

最大子段和问题
摘要:class Solution { public: int maxSubArray(int A[], int n) { int ans=A[0],i,j,sum=0; for(i=0;i<n;i++){ sum+=A[i]; ans=max(sum,ans); sum=max(sum,0); } re 阅读全文

posted @ 2017-12-11 22:10 flyingwaters 阅读(115) 评论(0) 推荐(0)

moore voting algorithm for majority element in vector
摘要:class Solution {public: int majorityElement(vector<int> &num) { int majorityIndex = 0; for (int count = 1, i = 1; i < num.size(); i++) { //遍历一遍vector< 阅读全文

posted @ 2017-11-28 14:39 flyingwaters 阅读(123) 评论(0) 推荐(0)

一道简单的局部链表反转的问题,具体解决时的麻烦的分类
摘要:这道leetcode题,看起来是十分简单的 但解决过程中,分类有些问题 Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, 阅读全文

posted @ 2017-11-12 16:45 flyingwaters 阅读(278) 评论(0) 推荐(0)

数学公式推导法解决问题
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. /// 如果按照常规的思想,我们可以遍历一遍节点,使用O(n)的空间复杂度,当然这就不需要人来思考了 /// 阅读全文

posted @ 2017-11-03 16:52 flyingwaters 阅读(375) 评论(0) 推荐(0)

分类解决问题的思想
摘要:Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2->3->4, you should return the list as 2->1->4->3. Your a 阅读全文

posted @ 2017-10-31 22:59 flyingwaters 阅读(167) 评论(0) 推荐(0)

Add to List 328. Odd Even Linked List
摘要:Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the 阅读全文

posted @ 2017-10-31 13:25 flyingwaters 阅读(153) 评论(0) 推荐(0)

一道leetcode习题的感想
摘要:Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 某个递归解法如下 虽然他是O(n)+O(n)但是灵活运用了栈,递归实 阅读全文

posted @ 2017-10-24 20:33 flyingwaters 阅读(142) 评论(0) 推荐(0)

STL中的vector和list的迭代器引申的关于迭代器的总结
摘要:迭代器(iterator)是连接容器和算法的纽带,为数据提供了抽象,使写算法的人不必关心各种数据结构的细节。迭代器提供了数据访问的标准模型——对象序列,使对容器更广泛的访问操作成为可能。 ////////// 泛型编程的关键所在,就是如何找到一种通用的方法,来访问具有不同结构的各种容器中的每个元素, 阅读全文

posted @ 2017-10-20 15:14 flyingwaters 阅读(345) 评论(0) 推荐(0)

C++中两种创建对象的方式
摘要:在C++中,为了让某个类只能通过new来创建(即如果直接创建对象,编译器将报错),应该() 正确答案: B 你的答案: D (错误) 将构造函数设为私有 将析构函数设为私有 将构造函数和析构函数均设为私有 没有办法能做到 正确答案: B 你的答案: D (错误) 将构造函数设为私有 将析构函数设为私 阅读全文

posted @ 2017-10-11 22:59 flyingwaters 阅读(1676) 评论(0) 推荐(0)

virtual关键字可以添加在什么上
摘要:只需要记住可以声明成虚函数的就行!(普通的成员函数或析构函数) 虚函数的使用原则:可以把public或protected的部分成员函数声明为虚函数; C++中的析构函数通常是虚析构函数; 构造函数不能声明为虚函数; 虚函数不能声明为静态的、全局的、友元的。 解释一: 为什么构造函数不能为虚函数: 没 阅读全文

posted @ 2017-10-10 16:15 flyingwaters 阅读(142) 评论(0) 推荐(0)

C++中const修饰指针
摘要:const char *p="hello"; char *const p; 根据左定值,右定向,const在左侧指向的值无法改变 const在*的右侧指针的指向无法改变 在C++中指针初始化指向的字符串为常量在只读存储区;无法修改 栈中存放局部常量。 堆中存放malloc和new的动态申请的函数。 阅读全文

posted @ 2017-10-09 22:49 flyingwaters 阅读(141) 评论(0) 推荐(0)

一道O(n)+S(1)的leetcode题大神stephan的简要解析
摘要:class Solution {public: void wiggleSort(vector<int>& nums) { int n = nums.size(); // Find a median. auto midptr = nums.begin() + n / 2; nth_element(nu 阅读全文

posted @ 2017-10-09 12:47 flyingwaters 阅读(229) 评论(0) 推荐(0)

总结数据长度问题
摘要:1. unsigned short i,j; for(i=0, j=2; i!=j; i+=5, j+=7) {} 2. unsigned short i,j; for(i=3,j=7;i!=j;i+=3,j+=7) {} 问题分别执行多少次? 解: unsigned short i;取值范围为0- 阅读全文

posted @ 2017-10-07 21:51 flyingwaters 阅读(187) 评论(0) 推荐(0)

运算符号优先级的应用
摘要:在一道leetcode的题目中我们深刻 看到C++运算符优先级的应用 如下: 另外简易总结本题的思路: 遍历所有的字符串是必须的,一开始的我的思路如下 排序vector,特殊排序重写compare [](string &a,string &b){if(a.size()!=b.size()){retu 阅读全文

posted @ 2017-10-07 19:44 flyingwaters 阅读(291) 评论(0) 推荐(0)

C++刷题经验
摘要:cout输出流 格式控制符 他们在#include <iomanip>头文件中 setprecision(n)与setiosflags(ios::fixed)合用,可以控制小数点右边的数字个数 ???妈的记不住,记下来格式控制,setprecision(n)+setiosflags(ios::fix 阅读全文

posted @ 2017-10-06 11:34 flyingwaters 阅读(1421) 评论(0) 推荐(0)

C++ string注意事项
摘要:1:作为一个容器String是十分重要而常见的; 首先:#include <string> 使用前,然后在命名空间中使用加空间名;刷题时有事直接打using namespace std::string; using namespace std::cin;等等也可以直接usingnamespace s 阅读全文

posted @ 2017-10-05 23:03 flyingwaters 阅读(184) 评论(0) 推荐(0)

导航