C++
文章平均质量分 72
cxcbupt
这个作者很懒,什么都没留下…
展开
-
C++中参数传递的两种方式:传值与传址及它们的区别
#includeusing namespace std;void mySwap(int *p1,int *p2);int main(){ int a=12; int b=44; int *pa=&a; int *pb=&b; if(a<b){ mySwap1(a,b); //mySwap2(pa,pb); //mySwap3(pa,pb); //mySw原创 2015-03-25 09:54:44 · 6063 阅读 · 0 评论 -
C++实现冒泡排序
#includeusing namespace std;#define SIZE_A 8int main(){ void myshow(int* p,int length);//函数提前声明 int list[SIZE_A]={49,38,65,97,76,13,27,49}; cout<<"排序前:"<<endl; myshow(list,SIZE_A); //冒泡排序-原创 2015-05-05 11:16:14 · 1600 阅读 · 0 评论 -
C++实现有序表折半查找
1>算法思想:折半查找(Binary Search)的查找过程是:先确定等查记录所在范围(区间),然后逐步缩小范围直到找到或找不到该记录为止。2>算法3>算法实现#includeusing namespace std;#define ARRAY_SIZE 11/*description:在标准输出设备上显示数组元素。parameter:int* p:指向整形数组原创 2015-05-12 10:10:26 · 9848 阅读 · 0 评论 -
C++实现快速排序
2》C++实现#includeusing namespace std;#define ARRAY_SIZE 8+1//有一个位置是枢轴记录/*description:在标准输出设备上显示数组元素。parameter:int* p:指向整形数组首元素的指针int length:整形数据长度*/void myshow(int* p,int length){ for(int原创 2015-05-07 17:16:11 · 525 阅读 · 0 评论 -
C++实现简单选择排序
1>算法思想2>算法实现#includeusing namespace std;#define ARRAY_SIZE 8/*description:在标准输出设备上显示数组元素。parameter:int* p:指向整形数组首元素的指针int length:整形数据长度*/void myshow(int* p,int length){ for(int i=0;原创 2015-05-11 15:26:05 · 652 阅读 · 0 评论 -
C++实现折半插入排序
在“C++实现直接插入排序 ”中,由于插入排序的基本操作是在一个有序表中进行查找和插入,则这个“查找”操作可以利用“折半查找”来实现,由此进行的插入排序称之为折半插入排序实现如下:#includeusing namespace std;#define SIZE_A 9int main(){ void myshow(int* p,int length);//函数提前声明原创 2015-04-29 16:52:43 · 2207 阅读 · 0 评论 -
两个有序线性表的合并(线性表使用 Vector表示)
#include#includeusing namespace std;#define SIZE_A 2#define SIZE_B 3#define SIZE_AB SIZE_A+SIZE_B //2+3=5int main(){ void showVector(vector *vector_p);//函数提前声明 vector list_a; vector list_b原创 2015-04-29 11:07:12 · 1869 阅读 · 0 评论 -
C++基类与派生类的转换与多态性
1》首先建立一个基类Student类头文件Student.h 如下:#ifndef Student_h#define Student_h#includeusing namespace std;/*基类Student头文件*/class Student{protected: int num; string name; float score;public: Stu原创 2015-04-09 11:41:19 · 855 阅读 · 2 评论 -
C++中变量使用前一定要初始化
在C++中变量声明后,在使用前一定要初始化。1>如下代码:#includeusing namespace std;int main(){ for(int i=0;i<100;i++){ int sum;//这里只是声明,未进行初始化 for(int j=1;j<100;j++){ sum+=j; } cout<<"sum["<<i<<"]:"<<sum<<原创 2015-04-16 16:00:36 · 4225 阅读 · 1 评论 -
Interface classes
An interface class is a class that has no members variables, and where all of the functions are pure virtual!(接口类是一个没有任何成员变量并且所有的函数都是纯虚函数的类。) In other words, the class is purely a definition, and转载 2015-04-10 15:10:26 · 517 阅读 · 0 评论 -
What and where are the stack and heap?
The stack is the memory set aside as scratch space for a thread of execution. When a function is called, a block is reserved on the top of the stack for local variables and some bookkeeping data.转载 2015-04-10 09:28:45 · 420 阅读 · 0 评论 -
Memory : Stack vs Heap
Stack vs HeapSo far we have seen how to declare basic type variables such as int,double, etc, and complex types such as arrays and structs. The way we have been declaring them so far, with转载 2015-04-10 09:12:15 · 1078 阅读 · 0 评论 -
虚函数(Virtual Function)与 纯虚函数(Pure Virtual Function)
1>虚函数(Virtual Function)1.1>Base Class #ifndef Animal_h#define Animal_h#include class Animal{protected: std::string m_strName; // We're making this constructor protected because // we don'转载 2015-04-10 14:25:42 · 1593 阅读 · 0 评论 -
warning C4552: '>>' : operator has no effect; expected operator with side-effect
1》编写一个自定义的函数shift_right:利用引用形参实现对一个int型的数据右移n位。代码如下:#includeusing namespace std;void shift_right(int &num,int n);int main(){ int num=8; cout<<"before shift ,num:"<<num<<endl; shift_right(n原创 2015-03-24 15:12:58 · 10479 阅读 · 0 评论 -
C++中关于内部与外部函数
1》如果一个函数只能被本文件中其他函数所调用 ,它称为内部函数,又称为静态(static)函数。内部函数首部的一般形式为:static 类型标识符 函数史(形参表)static int func (int a, int b)可以使内部函数只局限于所在的文件内。如果在不同的文件中有同名的内部函数,互不干扰。这样不同的人可以分别编原创 2015-03-20 18:28:27 · 2425 阅读 · 0 评论 -
循环右移,要求时间复杂度为O(n)且尽可能的少使用辅助空间
#includeusing namespace std;#define ARRAY_LENGTH 9int main(){ extern void shiftRight(int *arr ,int begin ,int k); extern void show(int *arr ,int length); int arr[]={1,2,3,4,5,6,7,8,9}; cout<<"循原创 2015-05-19 09:43:33 · 973 阅读 · 0 评论