c++递归学习_组合_普通选择性组合排列



c++递归学习_组合_普通选择性组合排列。

Sample Input
5 3

1 2 3 4 5

Sample Output

123

124

125

134


135

145

234

235

245

345

[cpp] view plaincopy
#include <iostream>
using namespace std;
const int len = 10;
int totalN;
int selectM;
int mat[len];
int result[len];
vo[......]

Read more

c++非重复生成全子集组合排列(含重复数字时,生成不重复全子集组合排列)

c++非重复生成全子集组合排列(含重复数字时,生成不重复全子集组合排列)。

Sample Input

4

1 2 2 3

Sample Output

1

12

122

1223

123

13

2

22

223

23

3

如果采用上篇文章的程序(处理不含重复数),运行的结果是:

以上均为重复数据,上标表示在原数据中使用的是重复数据的第几个数据,这就多出来好几种。

出现这种情况的原因是:在mat中存有重复的数据,在赋值的时候,仍然把这些数据取出直接赋值到数组result中。

要[......]

Read more

c++递归实例源码学习_组合_生成全子集组合排列(不含空集)

c++递归学习_组合_生成全子集组合排列(不含空集)。

Sample Input

4

1 2 3 4

Sample Output

1

12

123

1234

124

13

134

14

2

23

234

24

3

34

4

[cpp] view plaincopy
#include <iostream>
using namespace std;
const int len=10;
//为了让递归函数的参数更加简洁,把这些定义为全局变量
int n;//数[......]

Read more

c++三叉链表实现二叉树

三叉链表实现二叉树,VS2005可以运行通过。程序参考了许多大牛的总结,因能力有限,如有问题,请各位大牛指正。

二叉树采用三叉链表,实现了二叉树的构造、遍历、深度、宽度、结点个数、叶子个数 以及 结点的交换、层次、祖先、双亲、左孩子、右孩子、左兄弟、右兄弟各种功能

[cpp] view plaincopy
#include <iostream>
using namespace std;
const int MaxBTreeSize = 20;
template<class T>
class BTNode
{
public:
T data;[......]

Read more

c++使用单链表实现链栈

c++使用单链表实现链栈,使用单链表实现链栈,单链表不含头结点

公有三种方法:

1、把单链表类作为栈类的私有变量

2、把单链表类作为栈类的基类,使用继承的思想

3、把栈类作为单链表类的友元,这里略去

方法一:单链表类作为链栈的私有变量

问题:VS2005可以运行通过,但是dev通不过,不知道为什么,请各位大牛指正。

[cpp] view plaincopy
#include <iostream>
using namespace std;
template<class Type>
//定义结点
struct Node[......]

Read more

《如果》诗句英文原版与相关的翻译芮成钢鲁豫有约

《如果》诗句原版与相关的翻译芮成钢鲁豫有约。

If you can keep your head when all about you
Are losing theirs and blaming it on you;
If you can trust yourself when all men doubt you,
But make allowance for their doubting too;
If you can wait and not be tired by waiting,
Or, being lied about,don’t deal in lies,
Or,[......]

Read more

c++动态数组实现栈

c++动态数组实现栈。VS2005运行通过,如有问题,请各位大牛指正。

[cpp] view plaincopy
/*动态栈的条件
栈顶初始值:top=0;
栈顶:总是指向刚刚压入值的下一单元
栈空:top=0
栈满:top=Max (或者不存在栈满,可以继续申请空间)
入栈: data[top++] = NewItem;
出栈:newItem = data[--top];
*/

#include <iostream>
using namespace std;
const int StackIncreMent = 20;
template<c[......]

Read more

c++静态数组实现栈

c++静态数组实现栈。

VS2005运行通过,如有问题,请各位大牛指正。

  1. /*静态栈的条件
  2. 栈顶初始值:top=-1;
  3. 栈顶:总是指向刚刚压入的值
  4. 栈空:top=-1
  5. 栈满:top=Max-1
  6. 入栈: data[++top] = NewItem;
  7. 出栈:newItem = data[top--];
  8. */
  9. #include <iostream>
  10. using namespace std;
  11. const int Max = 50;
  12. template<clas[......]

Read more

c++单链表的一些操作链表的合并

c++单链表的一些操作链表的合并,单链表的一些操作,由于一些操作很类似,名字不好区分,现单列出来,可以直接在上篇文章的单链表中使用,VS2005调试通过

操作一:链表的合并

1、要求:两个单链表A和B,AB增C非增,C=A+B

注意:利用原表A和B,允许有相同元素

思想:

1、每次都插小的,大的留下继续比较

2、AB增C非增,则使用逆序插入

3、不能连续插入(每次要插入的结点总是要从原链表中截断,插入到C中)

代码:

  1. template<class Type>
  2. [......]

Read more

C++实现单链表实现实例源码

C++实现单链表实现实例源码,VS2005运行通过,如有问题,请各位大牛指正。

注意:单链表含有头结点

代码:

[cpp] view plaincopy
#include <iostream>
using namespace std;
template<class Type>
struct Node
{
Type data;
Node<Type> *next;
};
template<class Type>
class LinkList
{
protected:
int len;//链表中结点个数
N[......]

Read more