2012年5月29日

摘要: 抽象数据类型LinearList { //实例 0或多个元素的有序集合 //操作 Create (): 创建一个空线性表 Destroy (): 删除表 IsEmpty(): 如果表为空则返回t r u e,否则返回false Length (): 返回... 阅读全文
posted @ 2012-05-29 22:03 Buttonwood 阅读(215) 评论(0) 推荐(0) 编辑
 
摘要: #include except.hfloat *x;try {x = new float [n];}catch (xalloc) { // 仅当new 失败时才会进入 #include except.h cerr << "Out of Memory" << endl; exit( 1 ) ; }template <class T>void Make2DArray( T ** &x, int rows, int cols){ // 创建一个二维数组 // 不捕获异常 //创建行指针 x = new T * [rows]; //为每一 阅读全文
posted @ 2012-05-29 21:05 Buttonwood 阅读(1193) 评论(0) 推荐(0) 编辑

2012年5月28日

摘要: 一个程序咋爱内存占用的存储空间可以分为:程序区:用来存放可执行程序的程序代码的。静态存储区:静态变量,在程序开始执行时分配,在执行过程中是固定的,程序执行完后释放空间。动态存储区:动态变量和形参以及函数调用时的现场保护程序和返回地址等。auto变量(动态变量):C++编译器默认局部变量为自动变量。不需要auto关键字说明。若没有明确赋值,其初值是不确定的。int fun(int n){ auto int a; int b = 20;}static变量:静态变量static int x;//静态全局变量int fun(int n){ static int a;//静态局部变量,仍保留上一次函数调 阅读全文
posted @ 2012-05-28 21:26 Buttonwood 阅读(253) 评论(0) 推荐(0) 编辑
 
摘要: 函数的递归调用内联函数:(适用于比较短小,功能简单,经常调用的函数)。该机制将函数体的代码直接插入到函数调用处,将函数调用的方式改为顺序执行的插入的程序代码,以此来节省调用函数的时间开销。以空间(存储)换时间的方式。inline float max(float x,float y){ return (x>y?x:y);}1:除函数体内还有循环,switch和复杂嵌套的if语句外,所有的函数都可以定义为内联函数;2:内联函数也是定义在前,调用在后,形参与实参要一一对应;3:说明内联函数时,只是请求编译器调用时作为内联函数的扩展来实现,而不是命令;4:内联函数时一种空间换取时间的方法,需要取 阅读全文
posted @ 2012-05-28 20:52 Buttonwood 阅读(194) 评论(0) 推荐(0) 编辑
 
摘要: C++ 函数间的参数传递:传值,引用和地址void swap(int a, int b){ int t; t=a; a=b; b=t;}void main{ int a=10, b=20; cout<<"Before:a="<<a<<"\t"<<"b="<<b<<"\n"; swap(a,b); cout<<"After:a="<<a<<"\t"<<&quo 阅读全文
posted @ 2012-05-28 20:37 Buttonwood 阅读(343) 评论(0) 推荐(0) 编辑

2012年5月25日

摘要: int *y = new int; *y = 10; 或者 int *y = new int (10); 或者 int *y; y = new int (10); 一维数组: float *x = new float [n]; 在Borland C++中,当new 不能分配足够的空间时,它会引发(t h r o w)一个异常xalloc (在except.h 中定义)。可以采用try - ca... 阅读全文
posted @ 2012-05-25 21:28 Buttonwood 阅读(164) 评论(0) 推荐(0) 编辑
 
摘要: 传值函数:int Abc(int a, int b, int c){ return a+b+b*c+(a+b-c)/(a+b)+4;}模板函数:template<class T> T Abc(T a, T b, T c){ return a+b+b*c+(a+b-c)/(a+b)+4;}形式参数的用法会增加程序的运行开销类型T 的复制构造函数把相应的实际参数分别复制到形式参数a,b和... 阅读全文
posted @ 2012-05-25 20:47 Buttonwood 阅读(147) 评论(0) 推荐(0) 编辑

2012年5月21日

摘要: SAS与R语言的数据加载与转化 第一:R加载/调用SAS--在SAS中生成传送文件 LIBNAME SAS_R xport 'C:\sea.xpt';DATA SAS_R.sea;SET custdet1;RUN;--在R中读入library(foreign)library(Hmisc)sea<-sasxport.get("c:/sea.xpt")head(mydata)第二:SAS调用R的数据... 阅读全文
posted @ 2012-05-21 22:25 Buttonwood 阅读(674) 评论(0) 推荐(0) 编辑
 
摘要: 1a. choose rows where column 3 is larger than column 5:awk '$3>$5' input.txt > output.txt1b. calculate the sum of column 2 and 3 and put it at the end of a row:awk '{print $0,$2+$3}' input.txtor replace the first column:awk '{$1=$2+$3;print}' input.txt2. show rows betwe 阅读全文
posted @ 2012-05-21 20:57 Buttonwood 阅读(269) 评论(0) 推荐(0) 编辑
 
摘要: xargs是实现批量处理最方便的方法,掌握xargs能省下写许多不必要的脚本。下面已几个例子说明(某些只适用于GNU xargs):删除所有.txt文件,可以在子目录下:find . -name "*.txt" | xargs rm打包一个目录下所有.pl文件,可在深层子目录:find . -name "*.pl" | xargs tar -zcf perl.tar.gz提交一个文件所包含的所有命令(一个命令一行):cat myfile.sh | xargs -i echo qsub {} | shkill所有满足某个匹配的进程:ps -ax | awk 阅读全文
posted @ 2012-05-21 20:47 Buttonwood 阅读(1055) 评论(0) 推荐(0) 编辑