摘要: 数组类型的删除:template Error_code List::remove(int position,List_entry &x){if(count==0)return underflow;if(position=count)return rangeerror;x=entry[position];int i;for(i=position;iError_code List::remove(int position,List_entry &x){Node*q,*p;q=set_position(position-1);p=set_position(position);p=p- 阅读全文
posted @ 2013-09-24 08:52 没有颜色 阅读(180) 评论(0) 推荐(0)
摘要: 原程序定义了新的Stack 类 new_copy,会在执行完这段程序后,自动析构,将tope_node指向的内容析构掉。并且原程序没有对旧的top_node进行delete,造成内存流失。#includeusing namespace std;typedef char c;enum aa {success,underflow,overflow};struct Node{c entry;Node *next;Node(){next=NULL;}Node(c item,Node *a=NULL){entry=item;next=a;}};class Stack{public:Stack(){top 阅读全文
posted @ 2013-09-12 07:46 没有颜色 阅读(134) 评论(0) 推荐(0)
摘要: 指针的使用:指针可以被定义成不同类型,int ,float,char等等,也可以被定义成自定义指针。通过指针可以指向所需要用到的内容的地址,通过变换指针所指可以快速调去内容,减少操作时间。利用(*)p.和p->都可以指向所用内容。在排列中利用指针排序,可以减少操作量,避免程序丢失。指针在数组和结构体中利用广泛,对于调用指定数据很方便。 阅读全文
posted @ 2013-09-05 17:33 没有颜色 阅读(98) 评论(0) 推荐(0)
摘要: #includeusing namespace std;typedef char Node_entry;struct Node{Node_entry entry;Node *next;Node(){next=NULL;}Node(Node_entry item,Node*a=NULL){entry=item;next=a;}};int main(){Node*p0=new Node('0');Node*p1=(*p0).next=new Node('1',NULL);delete p1;delete p0;return 0;}#includeusing name 阅读全文
posted @ 2013-09-05 17:19 没有颜色 阅读(123) 评论(0) 推荐(0)
摘要: #includeusing namespace std;const int maxqueue=10;enum bb{success,overflow,underflow};class Queue{public:Queue(){count=0;rear=maxqueue-1;front=0;}bool empty() const{if((rear+1)%maxqueue==front)return true;else return false;}bb serve(int &i){if((rear+1)%maxqueue==front)return underflow;i=entry[fr 阅读全文
posted @ 2013-08-29 10:21 没有颜色 阅读(138) 评论(1) 推荐(0)
摘要: #includeusing namespace std;const int maxstack=5;enum bb{success,overflow,underflow};typedef int aa;class Stack{public:Stack(){count=0;}bool empty()const{bool cc=true;if(count>0)cc=false;return cc;}bb pop(){bb cc=success;if(count==0)cc=underflow;else--count;return cc;}bb top(aa &i)const{bb cc 阅读全文
posted @ 2013-08-28 17:15 没有颜色 阅读(135) 评论(0) 推荐(0)
摘要: #include#include //原文中没有此头文件using namespace std; int main(){int n;double item;stacknumbers;cout>n;for(int i=0;i>item;numbers.push(item);}cout<<endl<<endl;while(!numbers.empty()){cout<<numbers.top()<<"";numbers.pop();}cout<<endl;return 0; //原文没有返回值}此程序作用为 阅读全文
posted @ 2013-08-22 20:11 没有颜色 阅读(104) 评论(0) 推荐(0)
摘要: p56。 E4。当n=3时,有1,2,3总共3辆车,重排后有(123)(213)(132)(312)(321)5总形式。当n=4时,重排有(1324)(3214)(1234)(2134)(3124)(1423)(4213)(1243)(2143)(4123)(4312)(4132)(1432)(4321)14总形式。我们可以看到,第n辆车先出来的形式数=第n-1辆车先出来的形式数。可以看作n与n-1的转换例如:n=4时(1324)——>(1423)(3214)——>(4213)(1234)——>(1243)(2134)——>(2143)(3124)——>(4123 阅读全文
posted @ 2013-08-22 19:53 没有颜色 阅读(193) 评论(1) 推荐(0)
摘要: 通过对书本第一章的阅读(虽然有很多地方没看懂),但还是有很大收获的。对于编程原则我进行了如下总结和自我理解:1。在编写程序之前先明确自己想要完成的功能,可能用到的方法。2。对你要用到的程序,变量,函数等,明白他们的用处和目的,能解释他们。3。保持简洁但描述清楚。4。你编写的程序要清楚,至少令别人也能看懂。5。使用类来模拟程序的基本概念。6。正确利用函数。7。每个函数和类都应该有目的。8。尽量避免声明全局变量。9。如果必须使用全局变量,要记住他们用到哪去了。10。输入输出能轻易改变电脑系统。11。质量比数量更重要。12。有的错误编译时能发现,有的发现不了。13。一个好的程序,一半以上时间用于程序 阅读全文
posted @ 2013-08-20 22:12 没有颜色 阅读(130) 评论(0) 推荐(0)