
C++
文章平均质量分 71
云啊云
这个作者很懒,什么都没留下…
展开
-
C++ 传递数组的问题
转自http://blog.youkuaiyun.com/tanghw/article/details/6554538本文需要解决C++中关于数组的2个问题:1. 数组作为函数参数,传值还是传址?2. 函数参数中的数组元素个数能否确定?先看下面的代码。转载 2011-10-10 12:31:43 · 2049 阅读 · 0 评论 -
单链表的归并算法
转自 http://www.geeksforgeeks.org/archives/7740Merge Sort for Linked ListsMerge sort is often preferred for sorting a linked list. The slow random-access performance of a linked list转载 2011-10-27 11:26:15 · 813 阅读 · 0 评论 -
单链表的快速排序
单链表的快速排序和数组的快速排序在基本细想上是一致的,以从小到大来排序单链表为例,都是选择一个支点,然后把小于支点的元素放到左边,把大于支点的元素放到右边。 但是,由于单链表不能像数组那样随机存储,和数组的快排序相比较,还是有一些需要注意的细节: 1. 支点的选取,由于不能随机访问第K个元素,因此每次选择支点时可以取待排序那部分链表的头指针。 2. 遍历量表方式,由于不转载 2011-10-27 12:05:34 · 503 阅读 · 0 评论 -
递归计算二叉树的高度
//calculate height of binary tree if given the head nodeint Height_of_bTree(Node *node){ if (!node) { return 0; } if (node->left && node->right) { return max(Height_of_bTree(node->left)+原创 2011-10-24 05:34:48 · 1054 阅读 · 0 评论 -
单链表中判断是否存在环
转自http://blog.youkuaiyun.com/hitulric/article/details/6646121有一个单链表,其中可能有一个环,也就是某个节点的next指向的是链表中在它之前的节点,这样在链表的尾部形成一环。1、如何判断一个链表是不是这类链表?2、如果链表为存在环,如果找到环的入口点?扩展:判断两个单链表是否相交,如果相交,给出相交的第一个点。有一个单链表,其中可转载 2011-10-24 05:23:13 · 458 阅读 · 0 评论 -
sorting algorithms
from http://www.concentric.net/~ttwang/sort/sort.htmBubble SortExchange two adjacent elements if they are out of order. Repeat untilarray is sorted. This is a slow algorithm.Selection SortFi转载 2011-10-24 09:29:36 · 406 阅读 · 0 评论 -
为什么c语言中short的表示范围是-32768~32767
转自 http://hi.baidu.com/livetodaywell/blog/item/ded3924a9ce62ff983025ceb.html这得从二进制的原码说起: 如果以最高位为符号位,二进制原码最大为0111111111111111=2的15次方减1=32767 最小为1111111111111111=-2的15次方减1=-32767 此时0有两种表示方法,转载 2011-10-23 07:47:01 · 3474 阅读 · 0 评论 -
c++ const: const 变量, const 输入参数, const 返回值, const 成员函数
转载:http://blog.youkuaiyun.com/gamecreating/archive/2010/03/15/5382902.aspx看到const 关键字,C++程序员首先想到的可能是const 常量。这可不是良好的条件反射。如果只知道用const 定义常量,那么相当于把火药仅用于制作鞭炮。const 更大的魅力是它可以修饰函数的参数、返回值,甚至函数的定义体。const 是const转载 2011-10-23 09:28:29 · 348 阅读 · 0 评论 -
C++ 带有头结点的单链表的简单实现
#include using namespace std;struct Node { int data; Node * next;};class MyList{private: Node * head;public: MyList() { head = new Node; head->data = 0; head->next = NULL; } ~M原创 2011-10-24 08:47:56 · 919 阅读 · 0 评论 -
MergeSort 的实现
void Merge(int A[], int p, int q, int r){ int *L = new int[q-p+2]();//p...q int *R = new int[r-q]();//q+1...r for (int i=0;i<q-p+1;i++) { L[i]=A[p+i]; } L[q-p+1]=99999999; for (int i=0;i<原创 2011-10-24 05:32:46 · 439 阅读 · 0 评论 -
合并两个已排序的单链表的方法
转自 http://www.geeksforgeeks.org/archives/3622 前两种方法时间和空间上最好, 但个人觉得第三种递归的方法比较好理解Write a SortedMerge() function that takes two lists, each of which is sorted in increasing order, and merges转载 2011-10-27 10:49:42 · 685 阅读 · 0 评论