#include<iostream>
#define NUM 6
using namespace std;
typedef struct stack
{
int m;
struct stack *next;
}stack_node,*stack_link;
int StackEmpty(stack_link s);
void InitStack(stack_link *ss);
void push(stack_link *ss,int e);
void pop(stack_link *ss,int *e);
void TraverseStack(stack_link s);
void knapsack(int n);
void main()
{
int n;
system("cls");
knapsack(NUM);
cin>>n;
}
void knapsack(int n)
{
stack_link top;
int k=0;
InitStack(&top);
do
{
while(k<n)
{
push(&top,k);
TraverseStack(top);
k++;
}
pop(&top,&k);
k++;
}while(!StackEmpty(top));
}
void TraverseStack(stack_link s)
{
stack_link p=s;
printf("(");
while(!StackEmpty(p))
{
printf(" %3d ",p->m+1);
p=p->next;
}
printf(")/n/n");
}
void InitStack(stack_link *ss)
{
*ss=NULL;
}
void push(stack_link *ss,int e)
{
stack_link p;
p=(stack_link)malloc(sizeof(stack_node));
if(p)
{
p->m=e;
p->next=*ss;
*ss=p;
}
else
{
printf("Stack is overfollow!");
}
}
void pop(stack_link *ss,int *e)
{
stack_link p;
p=*ss;
if(!StackEmpty(p))
{
*ss=p->next;
*e=p->m;
free(p);
}
else
{
printf("stack is empty!");
}
}
int StackEmpty(stack_link s)
{
return s==NULL;
}