上一页 1 ··· 45 46 47 48 49 50 51 52 53 ··· 69 下一页
摘要: 静态成员函数,可以不通过对象来调用,即没有隐藏的this指针。virtual函数一定要通过对象来调用,即有隐藏的this指针。static成员没有this指针是关键!static function都是静态决议的(编译的时候就绑定了)而virtual function 是动态决议的(运行时候才绑定)例证#include #include using namespace std;class A { public: A(int a) { this->val2 = a; } static void get_val() { this->val2 = 4; cout <... 阅读全文
posted @ 2014-03-21 23:43 jihite 阅读(6977) 评论(1) 推荐(1)
摘要: 缘起#include #include using namespace std;class A { public: A() { cout #include using namespace std;class A { public: A() { cout #include using namespace std;class A { public: A() { cout << "default constructor!" << endl; } A(int i) { cout << "constr... 阅读全文
posted @ 2014-03-21 14:10 jihite 阅读(647) 评论(0) 推荐(1)
摘要: 事因#include using namespace std;struct A{ A(int) {} A() {} void fun() {};};int main(){ A a(2); a.fun(); A b(); b.fun();}编译错误解释A b(); 是函数声明,返回值为A, 函数名为b不信你看#include using namespace std;int main(){ int test(); cout using namespace std;int main(){ int test(); cout << test << e... 阅读全文
posted @ 2014-03-20 21:43 jihite 阅读(1189) 评论(0) 推荐(0)
摘要: 示例思路一:两个链表同时逐个遍历参考代码ListNode* combinList(ListNode *head_1, ListNode *head_2){ ListNode *head_3 = NULL; if(head_1 == NULL) { head_3 = head_2; } else if(head_2 == NULL) { head_3 = head_2; } else { ListNode *p1 = head_1; ListNode *p2 = head_2; ... 阅读全文
posted @ 2014-03-18 23:21 jihite 阅读(706) 评论(2) 推荐(1)
摘要: 策略直接遍历总数为len,再次遍历第len-k+1个就是答案,但是这样遍历了O(N+k)个,可以在O在更短的时间内找到图示参考代码#include using namespace std;typedef struct ListNode{ int value; ListNode* next;}ListNode;void createList(ListNode *&head){ head = new(ListNode); head->value = 1; head->next = NULL; ListNode *p2 = new(ListNode); p2... 阅读全文
posted @ 2014-03-18 16:48 jihite 阅读(2470) 评论(0) 推荐(0)
摘要: 案例数组内容:3 4 4 6 8 2 1 1 1调换奇偶:3 1 1 1 8 2 4 4 6思路源于快速排序方式1参考代码#include #include using namespace std;bool IsOdd(int num){ return num % 2 == 1 ? true ... 阅读全文
posted @ 2014-03-18 10:51 jihite 阅读(4472) 评论(2) 推荐(0)
摘要: 比如n = 2那么从1一直输出到99分析直接输出,遇到大数时肯定有问题,比如n=100,存储100位的数据类型不存在。可以利用数组来存储大数,比如n=100,可以开辟个数组 char a[101]思路一模拟现实中的技术方式,逢九进一参考代码#include #include using namespace std;bool minuxOne(char *a, int *end_index, int size){ if((*end_index == size - 1 && a[size - 1] == '0') || *end_index = size) retu 阅读全文
posted @ 2014-03-18 10:08 jihite 阅读(2870) 评论(0) 推荐(0)
摘要: argc是参数个数,定义为intargv是字符串数组,存的是参数,定义为char**或者char* argv[]比如你编译好的程序为my.exe在命令行执行 my.exe 1 2 3那argc就是4,argv[0]是"my.exe",argv[1]是"1",argv[2]是"2",argv[3]是"3"; 阅读全文
posted @ 2014-03-16 22:59 jihite 阅读(13779) 评论(0) 推荐(3)
摘要: 传值操作#include using namespace std;struct ListNode{ int m_nValue; ListNode* m_pNext;};void createList(ListNode *head){ head = new(ListNode); head->m_nValue = 1; head->m_pNext = NULL;}void deleteList(ListNode *p){ ListNode *next = NULL; while(p != NULL) { cout m_nValue m_... 阅读全文
posted @ 2014-03-16 17:46 jihite 阅读(568) 评论(0) 推荐(0)
摘要: 题目给定单链表头指针和一个结点指针,定义一个函数在O(1)时间内删除该结点。分析对于上图实例链表(a)删除指针p有两种方式思路1:(b)找到前一个指针pre,赋值pre->next = p->next,删掉p思路2:(c)目的是删除p,但是不删p,直接用p->next的值赋值给p,把p->next删除掉(好处:不用遍历找到p的前一个指针pre,O(1)时间内搞定)于是,定位到思路2,但是思路2有两个特例:删除的是尾指针,需要遍历找到前一个指针整个链表就一个结点(属于删尾指针,但没法找到前面的指针,需要开小灶单独处理)大体算法思路待删指针不是尾指针: 待删指针的值用待删指 阅读全文
posted @ 2014-03-16 17:06 jihite 阅读(5787) 评论(3) 推荐(1)
上一页 1 ··· 45 46 47 48 49 50 51 52 53 ··· 69 下一页