"act.h"
/*
* File: act.h
* Author: Napoleon
*
*/
#ifndef _ACT_H
#define _ACT_H
class act{
static int number;
public:
act();
act(const act& orig);
virtual ~act();
void Perm(int list[], int k, int m);
void setList(int *list,int length);
void SubSet(int *List, int m, int *Buffer, int flag);
void Output(int *Buffer, int flag);
int Index(int *List, int c);
private:
};
#endif /* _ACT_H */
"act.cpp"
/*
* File: act.cpp
* Author: Napoleon
*
*/
#include "act.h"
#include <stdio.h>
#include <iostream.h>
using namespace std;
inline void Swap(int& a, int& b);
int ListLength;
void SubSet(int *List, int m, int *Buffer, int flag);
void Output(int *Buffer, int flag);
int Index(int *List, int c);
act::act() {
}
act::act(const act& orig) {
}
act::~act() {
}
void setList(int *list,int length) {
ListLength = length;
int *Buffer=new int[ListLength];
for(int i=0;i<ListLength;i++)
Buffer[i]=' ';
SubSet(list,0,Buffer,0);
}
void Perm(int list[], int k, int m) {
int i;
if (k == m) {
for (i = 0; i <= m; i++) {
cout << list[i];
}
cout << endl;
} else {
for (i = k; i <= m; i++) {
Swap(list[k], list[i]);
Perm(list, k + 1, m);
Swap(list[k], list[i]);
}
}
}
inline void Swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
int Index(int *List, int c)
{
for(int i=0; i<=ListLength-1; i++)
{
if(c==List[i])
{
return i;
break;
}
}
return -1;
}
void SubSet(int *List, int m, int *Buffer, int flag)
{ void Output(int *Buffer, int flag);
if(m <= ListLength-1)
{
for(int i=(flag==0) ? 0 : Index(List,Buffer[flag-1])+1; i<=ListLength-1; i++)
{
Buffer[flag]=List[i];
Output(Buffer,flag);
SubSet(List, m+1, Buffer,flag+1);
}
}
//return;
}
void Output(int *Buffer, int flag)
{
static int count=1;
if(count==1)
{
cout<<count++<<": { }"<<endl;
}
cout<<count++<<": {";
for(int i=0; i<=flag; i++)
{
cout<<Buffer[i];
}
cout<<"}"<<endl;
}
"Main.cpp"
/*
* File: Main.cpp
* Author: Napoleon
*
*/
#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>
#include "act.h"
void Perm(int list[], int k, int m);
void setList(int *list,int length);
int main() {
cout << "Please input the number of all your numbers!" << "/n";
int num;
cin >> num;
cout << "Now,input all the numbers(one in a line.)" << "/n";
int queue[num];
for (int i = 0; i < num; i++) {
cin >> queue[i];
}
cout << "Now I will output all the sequences of them." << "/n";
Perm(queue, 0, num - 1);
cout << "/n";
cout << "Then all of its subsets are shown below:/n";
setList(queue,num);
return (EXIT_SUCCESS);
}
/*
* File: act.h
* Author: Napoleon
*
*/
#ifndef _ACT_H
#define _ACT_H
class act{
static int number;
public:
act();
act(const act& orig);
virtual ~act();
void Perm(int list[], int k, int m);
void setList(int *list,int length);
void SubSet(int *List, int m, int *Buffer, int flag);
void Output(int *Buffer, int flag);
int Index(int *List, int c);
private:
};
#endif /* _ACT_H */
"act.cpp"
/*
* File: act.cpp
* Author: Napoleon
*
*/
#include "act.h"
#include <stdio.h>
#include <iostream.h>
using namespace std;
inline void Swap(int& a, int& b);
int ListLength;
void SubSet(int *List, int m, int *Buffer, int flag);
void Output(int *Buffer, int flag);
int Index(int *List, int c);
act::act() {
}
act::act(const act& orig) {
}
act::~act() {
}
void setList(int *list,int length) {
ListLength = length;
int *Buffer=new int[ListLength];
for(int i=0;i<ListLength;i++)
Buffer[i]=' ';
SubSet(list,0,Buffer,0);
}
void Perm(int list[], int k, int m) {
int i;
if (k == m) {
for (i = 0; i <= m; i++) {
cout << list[i];
}
cout << endl;
} else {
for (i = k; i <= m; i++) {
Swap(list[k], list[i]);
Perm(list, k + 1, m);
Swap(list[k], list[i]);
}
}
}
inline void Swap(int& a, int& b) {
int temp = a;
a = b;
b = temp;
}
int Index(int *List, int c)
{
for(int i=0; i<=ListLength-1; i++)
{
if(c==List[i])
{
return i;
break;
}
}
return -1;
}
void SubSet(int *List, int m, int *Buffer, int flag)
{ void Output(int *Buffer, int flag);
if(m <= ListLength-1)
{
for(int i=(flag==0) ? 0 : Index(List,Buffer[flag-1])+1; i<=ListLength-1; i++)
{
Buffer[flag]=List[i];
Output(Buffer,flag);
SubSet(List, m+1, Buffer,flag+1);
}
}
//return;
}
void Output(int *Buffer, int flag)
{
static int count=1;
if(count==1)
{
cout<<count++<<": { }"<<endl;
}
cout<<count++<<": {";
for(int i=0; i<=flag; i++)
{
cout<<Buffer[i];
}
cout<<"}"<<endl;
}
"Main.cpp"
/*
* File: Main.cpp
* Author: Napoleon
*
*/
#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>
#include "act.h"
void Perm(int list[], int k, int m);
void setList(int *list,int length);
int main() {
cout << "Please input the number of all your numbers!" << "/n";
int num;
cin >> num;
cout << "Now,input all the numbers(one in a line.)" << "/n";
int queue[num];
for (int i = 0; i < num; i++) {
cin >> queue[i];
}
cout << "Now I will output all the sequences of them." << "/n";
Perm(queue, 0, num - 1);
cout << "/n";
cout << "Then all of its subsets are shown below:/n";
setList(queue,num);
return (EXIT_SUCCESS);
}