摘要: View Code 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 5 template<class Type> class List 6 { 7 private: 8 template<class T> class LinkNode 9 { 10 public: 11 LinkNode<Type>* link; 12 Type data; 13 14 LinkNode(LinkNode<Type>* ptr=NUL... 阅读全文
posted @ 2011-11-12 00:36 YipWingTim 阅读(256) 评论(0) 推荐(0) 编辑
摘要: View Code 1 //环的问题、拆环。 2 #include<iostream> 3 using namespace std; 4 5 template<class Type> class LinkNode 6 { 7 public: 8 LinkNode<Type> *link; 9 Type data; 10 11 LinkNode(LinkNode<Type>* ptr=NULL) 12 { 13 link=ptr; 14 } 15 LinkNode(const Type& item,LinkN... 阅读全文
posted @ 2011-11-09 02:00 YipWingTim 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 二级链表的实现,以及把二级链表展开成一级链表,关键是数据结构的设计,这里我用了二级链表的节点类,它包括了两个指针,一个指向一个二级链表节点,一个指向单链表的头结点。生成一个二级链表默认构造函数是只含有一个头结点为二级链表节点(空),插入的时候是插入一个单链表指针不为空,但是二级链表节点为空的二级链表节点。View Code 1 //二级单链表 2 #include<iostream> 3 using namespace std; 4 5 template<class Type> struct LinkNode 6 { 7 public: 8 Type data; ... 阅读全文
posted @ 2011-11-08 20:23 YipWingTim 阅读(524) 评论(0) 推荐(0) 编辑
摘要: 要求是编写一个“找一对数字”的游戏,具体的output如下图:其他小的细节就是,如果没找到一对,那么就要重新盖住翻开的数字;比如上图的6和3,他们不是一对,那么在下一次找的时候他们都恢复到“*”的状态。 如果找到了一对,那么就让这一对数学一直在后面的游戏里面显示出来。当全部的“对子”都找到以后,询问玩家还要不要玩,如果要的话,就再重新随机16个数字,然后继续以上的步骤。实现没问题,但是有个细节逻辑没处理好。View Code 1 #include<iostream> 2 #include<ctime> 3 #include<cstring> 4 #inclu 阅读全文
posted @ 2011-11-08 07:30 YipWingTim 阅读(885) 评论(0) 推荐(0) 编辑
摘要: 尽量减少空间复杂度。View Code 1 //矩阵旋转,顺时针90,180,270度 2 3 #include<iostream> 4 using namespace std; 5 6 #define M 4 7 #define N 3 8 9 char source[M][N];10 char rotate1[N][M];11 char rotate2[M][N];12 char rotate3[N][M];13 14 15 16 17 void revolve1()18 {19 char *p=source[M-1]; //记住一点,b和&b[0]意思一样,都是行地址 阅读全文
posted @ 2011-11-08 07:23 YipWingTim 阅读(639) 评论(0) 推荐(0) 编辑
摘要: 思路清晰,代码自然就美,题目不难。告诫自己一点,写代码时候脑袋一定要安静,要想清楚。犯小错误纯粹是瞎折腾,浪费宝贵时间。View Code 1 #include<iostream> 2 using namespace std; 3 4 template<class Type> class List 5 { 6 private: 7 template<class T> class LinkNode 8 { 9 public:10 LinkNode<Type> *link;11 Type data;12 13 Li... 阅读全文
posted @ 2011-11-07 01:35 YipWingTim 阅读(403) 评论(0) 推荐(0) 编辑
摘要: 倒数第K个数和中间数。自己编码能力还不行,要多多加油才行啊!!!View Code 1 #include<iostream> 2 #include<string> 3 using namespace std; 4 5 template<class Type> class List 6 { 7 private: 8 template<class T> class LinkNode 9 { 10 public: 11 LinkNode<Type> *link; 12 Type data; 13 LinkN... 阅读全文
posted @ 2011-11-06 23:19 YipWingTim 阅读(323) 评论(0) 推荐(0) 编辑
摘要: View Code 1 //ListReverse 2 3 #include<iostream> 4 using namespace std; 5 6 template<class Type> class List 7 { 8 private: 9 template<class T> class LinkNode10 {11 public:12 Type data;13 LinkNode<Type>* link;14 LinkNode(LinkNode<Type> *ptr=NULL)15 {16 ... 阅读全文
posted @ 2011-11-05 02:22 YipWingTim 阅读(677) 评论(0) 推荐(0) 编辑
摘要: 传入一个数组如 {1,2,3,4,5,6,7} 将数组前面 head的一个子集移到数组末尾end如input numberOfElements=3,则{1,2,3,4,5,6,7}=>{4,5,6,7,1,2,3} input numberOfElements=5,则{1,2,3,4,5,6,7}=>{6,7,1,2,3,4,5} 如何写出该算法?方法一:用前部分逆置,后部分逆置,整个数组逆置。注意数组名作形参的时候,会退化为指针,所以用sizeof(a)/sizeof(a[0])是求不出数组长度的,目前只知道直接传入数组长度的方法。View Code 1 #include< 阅读全文
posted @ 2011-11-05 00:35 YipWingTim 阅读(173) 评论(0) 推荐(0) 编辑
摘要: 头文件LinkedList.hView Code 1 //LinkedList.h 2 #include<iostream> 3 #ifndef LINKEDLIST_H_INCLUDED 4 #define LINKEDLIST_H_INCLUDED 5 6 #endif // LINKEDLIST_H_INCLUDED 7 8 using namespace std; 9 10 //const int NULL=0; 11 12 template <class Type> struct LinkNode 13 { 14 public: 15 Type d... 阅读全文
posted @ 2011-11-03 00:50 YipWingTim 阅读(602) 评论(0) 推荐(0) 编辑