![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
iamlijiangtao
这个作者很懒,什么都没留下…
展开
-
二叉树 类
//biTreeNode class //==================================================================================//notation ://author :jiangtao//purpose: create a biTreeNode//=======================原创 2009-10-11 21:46:00 · 372 阅读 · 0 评论 -
cout<<字符数组 getline(流,string,delimit character) 遇到的问题
#include #include using namespace std;#include void main(){ cout<<"please input two line string : "<<endl;/* string str=NULL;//--used to store a string //============must be initialize.原创 2009-11-09 15:32:00 · 770 阅读 · 0 评论 -
if (infile.good())//==============当被注释掉会多输出两个空格。但存在时不输出最后的两个空格,为什么??
#include #include using namespace std;int main () { char c, str[256]; ifstream is; cout << "Enter the name of an existing text file: "; cin.get (str,256); is.open (str);原创 2009-11-09 15:48:00 · 1227 阅读 · 0 评论 -
infile.getline() infile.get() 出现的问题,还没有解决.换成 getline(infile,str) 就正常了。所以用高级类型更安全,以后应该用高级类型string等
#include #include using namespace std;#include void main(){ ifstream infile; infile.open("data.txt",ios::in); if (!infile) cerr<<"open the file fail."<<endl; if (!infile.is_open原创 2009-11-09 16:33:00 · 2414 阅读 · 0 评论 -
biTree 大数插入右子树,小数插入左子树,子函数create , insert
#include using namespace std;//--------------biTree node struct----------struct tree{ struct tree * left; int data; struct tree * right;};typedef struct tree treeNode;//-------- de原创 2009-11-16 20:17:00 · 536 阅读 · 0 评论 -
全局变量 静态全局变量 静态局部变量 局部变量
//------全局变量 静态全局变量-----------/*静态全局变量 全局变量就是 外部变量。外部变量就是全局变量。不管你定义在哪个文件中。所谓全局就是可以扩展其作用范围到其他文件。 而静态全局变量就不能扩展作用域到其他文件。 静态局部 与 局部变量 静态局部在多次调用他所在的函数时,不重新分配内存--保存其值,而局部变量重原创 2009-11-19 20:16:00 · 548 阅读 · 0 评论 -
二叉树 create addnew
#include using namespace std;//--------------biTree node struct----------struct tree{ struct tree * left; int data; struct tree * right;};typedef struct tree treeNode;//-------- de原创 2009-11-20 08:44:00 · 350 阅读 · 0 评论 -
插入排序
#include #include using namespace std;//----------compare ------------templateBOOL larger(elemtype b, elemtype a){ if (b>a) { return TRUE; } else //-------华为编程规范: 哪怕语句块只有一条语句也原创 2009-11-20 08:42:00 · 372 阅读 · 0 评论 -
测试 static 局部变量 与 局部变量的不同
/*测试: static 局部变量 与 局部变量的不同 执行结果:-->the 0th invoke the function func()accountStaticLocal = 1accountLocal = 1-->the 1th invoke the function func()accountStaticLocal = 2account原创 2009-11-26 18:53:00 · 413 阅读 · 0 评论 -
static 函数 不能为外部文件调用
测试 static 函数 的调用结果: 编译错误:error C2129: static function void __cdecl funcStatic(void) declared but not defined分析: 禁止外部文件调用 static 函数,仅仅 源文件中的函数可以调用static函数。否则出现上述编译错误。 #include原创 2009-11-26 20:01:00 · 3653 阅读 · 0 评论 -
朗讯笔试题目 凭记忆对题目,做上机实验,观察结果
#include using namespace std;#define INT charvoid main(){ int i=-1; cout<<" i = -1"<<endl; cout<<"十六进制 的 -1 :"<<hex<<i<<endl; cout<<"十进制的 -1 :"<<dec<< i<<endl; //---------原创 2009-12-03 09:37:00 · 490 阅读 · 0 评论 -
COM ATL 为何物 ,为何引入
什么是COM组件(转) COM是Component Object Model (组件对象模型)的缩写。 用户需要什么样的软件产品?这是一个多选题,但高效,健壮是肯定会被选种的。作为一名软件开发人员如何做才能满足用户的需要呢?必须要保证升级应用时不破坏与以前版本的向后兼容性。必须做到扩展系统服务时不依赖特定的操作系统。面向对象的程序设计显然是一次革命性的改变。采用面向对象的设计方法我们可原创 2009-12-06 22:06:00 · 623 阅读 · 0 评论 -
数的划分问题
/* 把I 分成 j份, 有多少种分法? 重要概念 : f(I,j) 表示 把 I 分成 j 份的分法。 分成两类: (1)有 1 的分法 (2)没有1 的分法 1 )没有1 分法: 先从I 中拿出j 分成j份,即j份中,已经有了1. 然后再把剩余的I - j 分成 j 份,这样所有份中都 >= 2 2 ) 有 1 分法: 先j 份中,拿出一份,用于放原创 2009-12-05 19:55:00 · 519 阅读 · 0 评论 -
文件, 文件流对象ofstream, 缓冲区, 三个不同的概念,关键 理解outfile.clear()作用的关键
(文件, 文件流对象ofstream, 缓冲区, 三个不同的概念,关键)(由于文件读取是通过缓冲区的,所以直接修改文件内容比较麻烦。)删除文件的部分内容: 方法一:建立新文件——可以新建一个文件,然后把想保留的内容转存入新文件,这样就起到间接删除文件内容的作用。 方法二:建立一个缓冲区buffer,修改内容,然后找对文件offset,把buffer原创 2009-12-06 17:45:00 · 5665 阅读 · 1 评论 -
typedef struct 出现的错误
typedef struct { Elemtype data; tNode* left; tNode* right;}tNode,*pNode,*pTree;出现以下错误:error C2143: syntax error : missing ; before *error C2501: tNode : missing storage-class原创 2010-04-27 14:17:00 · 2725 阅读 · 0 评论 -
腾讯笔试题目之一 最简单的那个
// assertQQ.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include #include using namespace std;long assertQQ(string str){ int length = str.len原创 2010-04-26 08:57:00 · 671 阅读 · 0 评论 -
二叉树的非递归遍历
/*总结:对于树的操作,最简单最直接的方式就是 递归。因为树本身就是一个典型的递归定义。当不要求速度时,尽量用递归,比较省时,省去调试时间。对于二叉树的非递归算法,最重要的是算法的思想。就是上文代码中的注释部分。代码其实是注释的直接翻译。思想最重要。思想不清,编译调试将耗费大量时间,算法就很难写出来。*/// test.c原创 2010-04-28 16:25:00 · 632 阅读 · 0 评论 -
判断回文 字符串的最后一个字符是'/0', 而不是'/n' ,基础知识都忘了
#include #include using namespace std;template BOOL cycle(elem* begin, elem* end){ while(begin <=end) { if (*begin!=*end) return FALSE; begin++; end--; } return TRUE;原创 2009-11-08 22:05:00 · 746 阅读 · 0 评论 -
对一个简单递归的 时间复杂度的分析
#include using namespace std;/************************************************************************//* 算法说明:本文算法来自,数据结构考研试题分析算法意义:编写递归算法,并分析时间复杂度 *//********原创 2009-11-02 22:21:00 · 1076 阅读 · 0 评论 -
infile.getline() infile.get() 出现的问题,还没有解决
#include #include using namespace std;//命名空间#include void main(){ ifstream infile; infile.open("data.txt",ios::in);//打开文件,以便后边读取内容 if (!infile)/*检查文件是否打开*/ cerr<<"open the原创 2009-11-09 15:37:00 · 6174 阅读 · 2 评论 -
插入排序
#include "stdafx.h"#include using namespace std;//对有序表做插入排序//注意序号【0】的数据职责是岗哨,不要存需要排序的数据void insertSort(int * list, int length){ for (int i=2;i<length;i++)//第一个元素为有序,然后后边依次插入 if(list[i原创 2009-10-12 22:12:00 · 330 阅读 · 3 评论 -
折半插入排序算法
#include using namespace std;template void bInsertSort(elemtype *L,int length){ elemtype watcher; for(int i =1;i<length;i++) { watcher = L[i];// 放入岗哨 // 用折半查找法寻找擦汗如位置 int low原创 2009-10-14 21:52:00 · 988 阅读 · 3 评论 -
c++ 中文件的输入输出 问题 必须注意
#include using namespace std;#include void main(){ ifstream input_file;/* input_file.open("data.txt",ios::in); char c; while(!input_file.eof()) { input_file.read((cha原创 2009-10-15 16:57:00 · 792 阅读 · 0 评论 -
简单的数组查找算法 出现的错误:数组不可以使用引用传址
#include using namespace std;//--------------------针对数组的,简单的查找------------------/**/template int searchArray(elemtype *array, elemtype e,int length)// const 去保数据不被修改{ //计算数组长度 fo原创 2009-10-16 18:17:00 · 442 阅读 · 0 评论 -
文件读写
//--------------------读写文件,结构体为单位---------------#include #include using namespace std;typedef struct{ int num;// ---------the number of the point float x;// ---------the x coordi原创 2009-10-20 21:59:00 · 327 阅读 · 0 评论 -
多维数组当一维处理,并用数组模拟向量,来计算向量点积
#include using namespace std;//------------------把多维数组当成一位来看待。用一个数组元素类型的指针指向第三行元素地址,然后输出//------------------理论依据: 多维数组实际存储时 是一维的,连续存放的----------------------------//------------------计算向量点积,用数组原创 2009-10-21 21:27:00 · 1441 阅读 · 0 评论 -
shell sort 希尔排序问题
//==========================由于无法解决子序列的长度问题所以算法不正确,关键: 在子函数中求数组的长度#include "iostream"using namespace std;//---------------插入排序-------------------------templatevoid shellSort(elemtype *arr原创 2009-10-19 22:40:00 · 444 阅读 · 0 评论 -
当从文件读入数据时,注意文件最后一个换行符
这个是换行符,换行符的ascall码是13.问题是为什么文件前面的换行符并没有读入,而最后一个就读入了呢???代码如下include using namespace std;#include void main(){ char* filename ="parameters.txt";//输入数据的文件名 char* result ="result.txt";//输原创 2009-10-27 10:28:00 · 1514 阅读 · 0 评论 -
制表符不是简单的八个字符,它的意思是光标跳到8的倍数处——最近的,8的倍数,的位置
#include using namespace std;void main(){ int i=0; cout<<"数据间隔一个制表符/t"<<endl; for (i=0;i<3;i++) { cout<<"/t"<<"我随便写的数据"; } cout<<endl;/************************************原创 2009-11-04 20:11:00 · 2029 阅读 · 0 评论 -
用模板来 帮助子函数动态获得数组的长度
#include using namespace std;template display(int (&a)[arrayLength]){ for(int i=0;i< arrayLength;i++) cout<<" "a[i];}void main(){ int a[5]={0,1,2,3,4}; display(&a[]);}原创 2009-10-28 22:30:00 · 579 阅读 · 0 评论 -
建立简单的链表 节点是结构体
#include using namespace std;#include #include //-----------------建立节点-------------typedef struct node { char* name; node* next;}NODE,HEAD;//-------------建立链表----------------原创 2009-10-27 22:34:00 · 1135 阅读 · 0 评论 -
关于多维数组做参数 的问题
#include using namespace std;//-----------------------多维数组作为参数-----------------------//-----------------------用多维数组多维形参,并输出数组-------//-------这种参数的定义格式算是重载,不与一下格式重读//-------错误:display原创 2009-10-28 21:46:00 · 797 阅读 · 0 评论 -
读取文件的重载符>是忽略 换行符的,而outfile.put(char), infile.get(char)不去忽略
#include using namespace std;#include //-------------- 测试打开文件夹中的文件是否正常,以前没有打开过文件夹中的文件,试试//void main(){ char* sourceFile ="cameraPoint/point2d.txt";//------------文件夹下的文件 char* objectFil原创 2009-10-28 22:41:00 · 1992 阅读 · 0 评论 -
文件流对象的重用, 必须用infile.close() infile.clear()
#include using namespace std;#include #include //-------------用一个文件流读取多个文件,注意关闭文件,再清空文件流状态-----------void main(){ /* int i=0;//----没有什么意义,只为while() 参数有个值来停止 while(i<3) { //以原创 2009-10-29 16:27:00 · 4368 阅读 · 0 评论 -
一个错误的链表程序 ——编译通过,执行出错。自己没有好的调试技术,没有找到错误;而靠经验得逐行细查——费时间
// list.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include using namespace std;typedef struct node { int no;//-------应该用公用体,以便头节点用来存储节点个数 node*原创 2009-11-06 18:42:00 · 470 阅读 · 0 评论 -
注意有指针参数的函数定义与函数实现 必须一致,编译器只检查是否是指针,而不管你的实参是几维指针
今天编辑代码发现,子函数定义为一维指针,而实现时为二维指针,主函数调用它时传递的是二维指针。此时,编译器报错,说不能把一个二维地址传给一维地址的指针。但是在VC++IDE中双击错误,定位时,直接跳转到子函数实现处,并没有提示你子函数定义与实现不同,也就是说,编译器不对指针所指数组维数和长度不进行检查。原创 2009-10-30 19:45:00 · 453 阅读 · 0 评论 -
换行符 不同软件不同对待,不同系统不同对待
不同的系统,不同的换行符。如果你的文件来自不同的系统,而你把它们混合使用,就必须注意:不同的系统,不同的换行符,比如windows 用/r/n,Unix用 /r, Mac 用/n。而软件Ultraedit打开文件时只对换行符判断一次。如果你拼接不同文件,则会出现一些逻辑错误,而你很难查找。UltraEdit 之后采用一种识别方式,一般是以三种换行符中的数量多的为准。 以最快的速度原创 2009-10-30 21:12:00 · 410 阅读 · 0 评论 -
第一次参加《有道难题》
有道难题的总结:设置结构体,按逻辑存储数据,便于后期逻辑处理只要有数据,很多先排序,会简化问题以下问题的关键:排序规则: (选修分数 - 90)* 学分值来做排序,而不是选修分数/学分值。这个排序规则是关键。我的问题:在刚开始编代码前,想思想。用到的是选修课的组合排列做测试。这样非常麻烦,比较次数太多。(应该用排序的,这样就可以一次搞定了。)然后原创 2010-05-30 22:17:00 · 635 阅读 · 0 评论