引用

作者在 2008-07-09 12:16:41 发布以下内容
引用
 
  C++里新增加了引用的概念。引用的最大优点就是不占用更多的内存,这样也省去了传参时的复制值的操作。尤其是对数组形式的参数,或者迭代函数来说具有价值。
  使用数组的引用,必须知道数组的大小。例如:void f(char (&list)[10]);
  如果不知道数组的长度,那么只有使用指针引用。指针引用是一个可行的方法。不过,必须是按照下面的方式来使用:
 
void F(int* &a,int &n);
 
int main()
{
       ......
       int* a;
       ......
       a=new int[10];//or int c[10]={0};a=c;
       ......
       F(a,10);
       ......
}
 
  或许,你会想:省略一个指针的传参的操作有意义吗?可以参看下面的这道题:
 
 
  链接里的题目中的函数,是一个递归的函数。每次传参都会传递指针参数,其实这些操作是可以省略的。如果把:void F(const T E[],int n,int x=0,int y=0),修改成:void F(const T* &E,const int &n,const int &x,int &y)。这样子,就能最大限度的减少空间的开销了。

  下面是修改后的版本。

程序:
 
#include <iostream>
using namespace std;
int* list;
template<class T>
void Print(const T* &E,const int &x)
{
 cout<<"{";
 for(int i=0;i<x-1;i++)
 {
  cout<<E[list[i]]<<", ";
 }
 cout<<E[list[x-1]]<<"} ";
}
template<class T>
void F(const T* &E,const int &n,const int &x,int &y)
{
 //本函数用来求出集合E中x个元素的所有子集
 if(x==0)
 {
  //0元素子集
  cout<<"{}";
  return;
 }
 if(x==n)
 {
  //全元素子集
  cout<<"{";
  for(int j=0;j<n-1;j++)
  {
   cout<<E[j]<<", ";
  }
  cout<<E[n-1]<<"}";
  return;
 }
 if(x>y)
 {
  //第一次取数
  if(y==0)
  {
   for(int k=0;k<n-x+1;k++)
   {
    list[y]=k;
    if(y==x-1)
    {
     Print(E,x);
    }
    else
    {
     y++;
     F(E,n,x,y);
     y--;
    }
   }
   return;
  }
  //取1个元素
  for(int i=list[y-1]+1;i<n-x+y+1;i++)
  {
   list[y]=i;
   if(y==x-1)
   {
    Print(E,x);
   }
   else
   {
    y++;
    F(E,n,x,y);
    y--;
   }
  }
  list[y]=0;
 }
}
template<class T>
void eXF(const T* &E,const int &n)
{
 list=new int[n];
 for(int i=0;i<=n;i++)
 {
  //分别求出0到n个元素的子集
  int y=0;
  F(E,n,i,y);
  cout<<endl;
 }
 delete [] list;
 list=0;
}
int main()
{
 char* a=new char[10];
 a[0]='a';
 a[1]='b';
 a[2]='c';
 a[3]='d';
 a[4]='e';
 a[5]='f';
 a[6]='g';
 a[7]='h';
 a[8]='i';
 a[9]='j';
 try
 {
  eXF(a,10);
 }
 catch(const char *s)
 {
  cout<<s<<endl;
  return 1;
 }
 delete [] a;
 a=0;
 cout<<endl<<endl;
 int* b=new int[5];
 b[0]=1;
 b[1]=2;
 b[2]=3;
 b[3]=4;
 b[4]=5;
 try
 {
  eXF(b,5);
 }
 catch(const char *s)
 {
  cout<<s<<endl;
  return 1;
 }
 return 0;
}
 
结果:
 
{}
{a} {b} {c} {d} {e} {f} {g} {h} {i} {j}
{a, b} {a, c} {a, d} {a, e} {a, f} {a, g} {a, h} {a, i} {a, j} {b, c} {b, d} {b,
 e} {b, f} {b, g} {b, h} {b, i} {b, j} {c, d} {c, e} {c, f} {c, g} {c, h} {c, i}
 {c, j} {d, e} {d, f} {d, g} {d, h} {d, i} {d, j} {e, f} {e, g} {e, h} {e, i} {e
, j} {f, g} {f, h} {f, i} {f, j} {g, h} {g, i} {g, j} {h, i} {h, j} {i, j}
{a, b, c} {a, b, d} {a, b, e} {a, b, f} {a, b, g} {a, b, h} {a, b, i} {a, b, j}
{a, c, d} {a, c, e} {a, c, f} {a, c, g} {a, c, h} {a, c, i} {a, c, j} {a, d, e}
{a, d, f} {a, d, g} {a, d, h} {a, d, i} {a, d, j} {a, e, f} {a, e, g} {a, e, h}
{a, e, i} {a, e, j} {a, f, g} {a, f, h} {a, f, i} {a, f, j} {a, g, h} {a, g, i}
{a, g, j} {a, h, i} {a, h, j} {a, i, j} {b, c, d} {b, c, e} {b, c, f} {b, c, g}
{b, c, h} {b, c, i} {b, c, j} {b, d, e} {b, d, f} {b, d, g} {b, d, h} {b, d, i}
{b, d, j} {b, e, f} {b, e, g} {b, e, h} {b, e, i} {b, e, j} {b, f, g} {b, f, h}
{b, f, i} {b, f, j} {b, g, h} {b, g, i} {b, g, j} {b, h, i} {b, h, j} {b, i, j}
{c, d, e} {c, d, f} {c, d, g} {c, d, h} {c, d, i} {c, d, j} {c, e, f} {c, e, g}
{c, e, h} {c, e, i} {c, e, j} {c, f, g} {c, f, h} {c, f, i} {c, f, j} {c, g, h}
{c, g, i} {c, g, j} {c, h, i} {c, h, j} {c, i, j} {d, e, f} {d, e, g} {d, e, h}
{d, e, i} {d, e, j} {d, f, g} {d, f, h} {d, f, i} {d, f, j} {d, g, h} {d, g, i}
{d, g, j} {d, h, i} {d, h, j} {d, i, j} {e, f, g} {e, f, h} {e, f, i} {e, f, j}
{e, g, h} {e, g, i} {e, g, j} {e, h, i} {e, h, j} {e, i, j} {f, g, h} {f, g, i}
{f, g, j} {f, h, i} {f, h, j} {f, i, j} {g, h, i} {g, h, j} {g, i, j} {h, i, j}
{a, b, c, d} {a, b, c, e} {a, b, c, f} {a, b, c, g} {a, b, c, h} {a, b, c, i} {a
, b, c, j} {a, b, d, e} {a, b, d, f} {a, b, d, g} {a, b, d, h} {a, b, d, i} {a,
b, d, j} {a, b, e, f} {a, b, e, g} {a, b, e, h} {a, b, e, i} {a, b, e, j} {a, b,
 f, g} {a, b, f, h} {a, b, f, i} {a, b, f, j} {a, b, g, h} {a, b, g, i} {a, b, g
, j} {a, b, h, i} {a, b, h, j} {a, b, i, j} {a, c, d, e} {a, c, d, f} {a, c, d,
g} {a, c, d, h} {a, c, d, i} {a, c, d, j} {a, c, e, f} {a, c, e, g} {a, c, e, h}
 {a, c, e, i} {a, c, e, j} {a, c, f, g} {a, c, f, h} {a, c, f, i} {a, c, f, j} {
a, c, g, h} {a, c, g, i} {a, c, g, j} {a, c, h, i} {a, c, h, j} {a, c, i, j} {a,
 d, e, f} {a, d, e, g} {a, d, e, h} {a, d, e, i} {a, d, e, j} {a, d, f, g} {a, d
, f, h} {a, d, f, i} {a, d, f, j} {a, d, g, h} {a, d, g, i} {a, d, g, j} {a, d,
h, i} {a, d, h, j} {a, d, i, j} {a, e, f, g} {a, e, f, h} {a, e, f, i} {a, e, f,
 j} {a, e, g, h} {a, e, g, i} {a, e, g, j} {a, e, h, i} {a, e, h, j} {a, e, i, j
} {a, f, g, h} {a, f, g, i} {a, f, g, j} {a, f, h, i} {a, f, h, j} {a, f, i, j}
{a, g, h, i} {a, g, h, j} {a, g, i, j} {a, h, i, j} {b, c, d, e} {b, c, d, f} {b
, c, d, g} {b, c, d, h} {b, c, d, i} {b, c, d, j} {b, c, e, f} {b, c, e, g} {b,
c, e, h} {b, c, e, i} {b, c, e, j} {b, c, f, g} {b, c, f, h} {b, c, f, i} {b, c,
 f, j} {b, c, g, h} {b, c, g, i} {b, c, g, j} {b, c, h, i} {b, c, h, j} {b, c, i
, j} {b, d, e, f} {b, d, e, g} {b, d, e, h} {b, d, e, i} {b, d, e, j} {b, d, f,
g} {b, d, f, h} {b, d, f, i} {b, d, f, j} {b, d, g, h} {b, d, g, i} {b, d, g, j}
 {b, d, h, i} {b, d, h, j} {b, d, i, j} {b, e, f, g} {b, e, f, h} {b, e, f, i} {
b, e, f, j} {b, e, g, h} {b, e, g, i} {b, e, g, j} {b, e, h, i} {b, e, h, j} {b,
 e, i, j} {b, f, g, h} {b, f, g, i} {b, f, g, j} {b, f, h, i} {b, f, h, j} {b, f
, i, j} {b, g, h, i} {b, g, h, j} {b, g, i, j} {b, h, i, j} {c, d, e, f} {c, d,
e, g} {c, d, e, h} {c, d, e, i} {c, d, e, j} {c, d, f, g} {c, d, f, h} {c, d, f,
 i} {c, d, f, j} {c, d, g, h} {c, d, g, i} {c, d, g, j} {c, d, h, i} {c, d, h, j
} {c, d, i, j} {c, e, f, g} {c, e, f, h} {c, e, f, i} {c, e, f, j} {c, e, g, h}
{c, e, g, i} {c, e, g, j} {c, e, h, i} {c, e, h, j} {c, e, i, j} {c, f, g, h} {c
, f, g, i} {c, f, g, j} {c, f, h, i} {c, f, h, j} {c, f, i, j} {c, g, h, i} {c,
g, h, j} {c, g, i, j} {c, h, i, j} {d, e, f, g} {d, e, f, h} {d, e, f, i} {d, e,
 f, j} {d, e, g, h} {d, e, g, i} {d, e, g, j} {d, e, h, i} {d, e, h, j} {d, e, i
, j} {d, f, g, h} {d, f, g, i} {d, f, g, j} {d, f, h, i} {d, f, h, j} {d, f, i,
j} {d, g, h, i} {d, g, h, j} {d, g, i, j} {d, h, i, j} {e, f, g, h} {e, f, g, i}
 {e, f, g, j} {e, f, h, i} {e, f, h, j} {e, f, i, j} {e, g, h, i} {e, g, h, j} {
e, g, i, j} {e, h, i, j} {f, g, h, i} {f, g, h, j} {f, g, i, j} {f, h, i, j} {g,
 h, i, j}
{a, b, c, d, e} {a, b, c, d, f} {a, b, c, d, g} {a, b, c, d, h} {a, b, c, d, i}
{a, b, c, d, j} {a, b, c, e, f} {a, b, c, e, g} {a, b, c, e, h} {a, b, c, e, i}
{a, b, c, e, j} {a, b, c, f, g} {a, b, c, f, h} {a, b, c, f, i} {a, b, c, f, j}
{a, b, c, g, h} {a, b, c, g, i} {a, b, c, g, j} {a, b, c, h, i} {a, b, c, h, j}
{a, b, c, i, j} {a, b, d, e, f} {a, b, d, e, g} {a, b, d, e, h} {a, b, d, e, i}
{a, b, d, e, j} {a, b, d, f, g} {a, b, d, f, h} {a, b, d, f, i} {a, b, d, f, j}
{a, b, d, g, h} {a, b, d, g, i} {a, b, d, g, j} {a, b, d, h, i} {a, b, d, h, j}
{a, b, d, i, j} {a, b, e, f, g} {a, b, e, f, h} {a, b, e, f, i} {a, b, e, f, j}
{a, b, e, g, h} {a, b, e, g, i} {a, b, e, g, j} {a, b, e, h, i} {a, b, e, h, j}
{a, b, e, i, j} {a, b, f, g, h} {a, b, f, g, i} {a, b, f, g, j} {a, b, f, h, i}
{a, b, f, h, j} {a, b, f, i, j} {a, b, g, h, i} {a, b, g, h, j} {a, b, g, i, j}
{a, b, h, i, j} {a, c, d, e, f} {a, c, d, e, g} {a, c, d, e, h} {a, c, d, e, i}
{a, c, d, e, j} {a, c, d, f, g} {a, c, d, f, h} {a, c, d, f, i} {a, c, d, f, j}
{a, c, d, g, h} {a, c, d, g, i} {a, c, d, g, j} {a, c, d, h, i} {a, c, d, h, j}
{a, c, d, i, j} {a, c, e, f, g} {a, c, e, f, h} {a, c, e, f, i} {a, c, e, f, j}
{a, c, e, g, h} {a, c, e, g, i} {a, c, e, g, j} {a, c, e, h, i} {a, c, e, h, j}
{a, c, e, i, j} {a, c, f, g, h} {a, c, f, g, i} {a, c, f, g, j} {a, c, f, h, i}
{a, c, f, h, j} {a, c, f, i, j} {a, c, g, h, i} {a, c, g, h, j} {a, c, g, i, j}
{a, c, h, i, j} {a, d, e, f, g} {a, d, e, f, h} {a, d, e, f, i} {a, d, e, f, j}
{a, d, e, g, h} {a, d, e, g, i} {a, d, e, g, j} {a, d, e, h, i} {a, d, e, h, j}
{a, d, e, i, j} {a, d, f, g, h} {a, d, f, g, i} {a, d, f, g, j} {a, d, f, h, i}
{a, d, f, h, j} {a, d, f, i, j} {a, d, g, h, i} {a, d, g, h, j} {a, d, g, i, j}
{a, d, h, i, j} {a, e, f, g, h} {a, e, f, g, i} {a, e, f, g, j} {a, e, f, h, i}
{a, e, f, h, j} {a, e, f, i, j} {a, e, g, h, i} {a, e, g, h, j} {a, e, g, i, j}
{a, e, h, i, j} {a, f, g, h, i} {a, f, g, h, j} {a, f, g, i, j} {a, f, h, i, j}
{a, g, h, i, j} {b, c, d, e, f} {b, c, d, e, g} {b, c, d, e, h} {b, c, d, e, i}
{b, c, d, e, j} {b, c, d, f, g} {b, c, d, f, h} {b, c, d, f, i} {b, c, d, f, j}
{b, c, d, g, h} {b, c, d, g, i} {b, c, d, g, j} {b, c, d, h, i} {b, c, d, h, j}
{b, c, d, i, j} {b, c, e, f, g} {b, c, e, f, h} {b, c, e, f, i} {b, c, e, f, j}
{b, c, e, g, h} {b, c, e, g, i} {b, c, e, g, j} {b, c, e, h, i} {b, c, e, h, j}
{b, c, e, i, j} {b, c, f, g, h} {b, c, f, g, i} {b, c, f, g, j} {b, c, f, h, i}
{b, c, f, h, j} {b, c, f, i, j} {b, c, g, h, i} {b, c, g, h, j} {b, c, g, i, j}
{b, c, h, i, j} {b, d, e, f, g} {b, d, e, f, h} {b, d, e, f, i} {b, d, e, f, j}
{b, d, e, g, h} {b, d, e, g, i} {b, d, e, g, j} {b, d, e, h, i} {b, d, e, h, j}
{b, d, e, i, j} {b, d, f, g, h} {b, d, f, g, i} {b, d, f, g, j} {b, d, f, h, i}
{b, d, f, h, j} {b, d, f, i, j} {b, d, g, h, i} {b, d, g, h, j} {b, d, g, i, j}
{b, d, h, i, j} {b, e, f, g, h} {b, e, f, g, i} {b, e, f, g, j} {b, e, f, h, i}
{b, e, f, h, j} {b, e, f, i, j} {b, e, g, h, i} {b, e, g, h, j} {b, e, g, i, j}
{b, e, h, i, j} {b, f, g, h, i} {b, f, g, h, j} {b, f, g, i, j} {b, f, h, i, j}
{b, g, h, i, j} {c, d, e, f, g} {c, d, e, f, h} {c, d, e, f, i} {c, d, e, f, j}
{c, d, e, g, h} {c, d, e, g, i} {c, d, e, g, j} {c, d, e, h, i} {c, d, e, h, j}
{c, d, e, i, j} {c, d, f, g, h} {c, d, f, g, i} {c, d, f, g, j} {c, d, f, h, i}
{c, d, f, h, j} {c, d, f, i, j} {c, d, g, h, i} {c, d, g, h, j} {c, d, g, i, j}
{c, d, h, i, j} {c, e, f, g, h} {c, e, f, g, i} {c, e, f, g, j} {c, e, f, h, i}
{c, e, f, h, j} {c, e, f, i, j} {c, e, g, h, i} {c, e, g, h, j} {c, e, g, i, j}
{c, e, h, i, j} {c, f, g, h, i} {c, f, g, h, j} {c, f, g, i, j} {c, f, h, i, j}
{c, g, h, i, j} {d, e, f, g, h} {d, e, f, g, i} {d, e, f, g, j} {d, e, f, h, i}
{d, e, f, h, j} {d, e, f, i, j} {d, e, g, h, i} {d, e, g, h, j} {d, e, g, i, j}
{d, e, h, i, j} {d, f, g, h, i} {d, f, g, h, j} {d, f, g, i, j} {d, f, h, i, j}
{d, g, h, i, j} {e, f, g, h, i} {e, f, g, h, j} {e, f, g, i, j} {e, f, h, i, j}
{e, g, h, i, j} {f, g, h, i, j}
{a, b, c, d, e, f} {a, b, c, d, e, g} {a, b, c, d, e, h} {a, b, c, d, e, i} {a,
b, c, d, e, j} {a, b, c, d, f, g} {a, b, c, d, f, h} {a, b, c, d, f, i} {a, b, c
, d, f, j} {a, b, c, d, g, h} {a, b, c, d, g, i} {a, b, c, d, g, j} {a, b, c, d,
 h, i} {a, b, c, d, h, j} {a, b, c, d, i, j} {a, b, c, e, f, g} {a, b, c, e, f,
h} {a, b, c, e, f, i} {a, b, c, e, f, j} {a, b, c, e, g, h} {a, b, c, e, g, i} {
a, b, c, e, g, j} {a, b, c, e, h, i} {a, b, c, e, h, j} {a, b, c, e, i, j} {a, b
, c, f, g, h} {a, b, c, f, g, i} {a, b, c, f, g, j} {a, b, c, f, h, i} {a, b, c,
 f, h, j} {a, b, c, f, i, j} {a, b, c, g, h, i} {a, b, c, g, h, j} {a, b, c, g,
i, j} {a, b, c, h, i, j} {a, b, d, e, f, g} {a, b, d, e, f, h} {a, b, d, e, f, i
} {a, b, d, e, f, j} {a, b, d, e, g, h} {a, b, d, e, g, i} {a, b, d, e, g, j} {a
, b, d, e, h, i} {a, b, d, e, h, j} {a, b, d, e, i, j} {a, b, d, f, g, h} {a, b,
 d, f, g, i} {a, b, d, f, g, j} {a, b, d, f, h, i} {a, b, d, f, h, j} {a, b, d,
f, i, j} {a, b, d, g, h, i} {a, b, d, g, h, j} {a, b, d, g, i, j} {a, b, d, h, i
, j} {a, b, e, f, g, h} {a, b, e, f, g, i} {a, b, e, f, g, j} {a, b, e, f, h, i}
 {a, b, e, f, h, j} {a, b, e, f, i, j} {a, b, e, g, h, i} {a, b, e, g, h, j} {a,
 b, e, g, i, j} {a, b, e, h, i, j} {a, b, f, g, h, i} {a, b, f, g, h, j} {a, b,
f, g, i, j} {a, b, f, h, i, j} {a, b, g, h, i, j} {a, c, d, e, f, g} {a, c, d, e
, f, h} {a, c, d, e, f, i} {a, c, d, e, f, j} {a, c, d, e, g, h} {a, c, d, e, g,
 i} {a, c, d, e, g, j} {a, c, d, e, h, i} {a, c, d, e, h, j} {a, c, d, e, i, j}
{a, c, d, f, g, h} {a, c, d, f, g, i} {a, c, d, f, g, j} {a, c, d, f, h, i} {a,
c, d, f, h, j} {a, c, d, f, i, j} {a, c, d, g, h, i} {a, c, d, g, h, j} {a, c, d
, g, i, j} {a, c, d, h, i, j} {a, c, e, f, g, h} {a, c, e, f, g, i} {a, c, e, f,
 g, j} {a, c, e, f, h, i} {a, c, e, f, h, j} {a, c, e, f, i, j} {a, c, e, g, h,
i} {a, c, e, g, h, j} {a, c, e, g, i, j} {a, c, e, h, i, j} {a, c, f, g, h, i} {
a, c, f, g, h, j} {a, c, f, g, i, j} {a, c, f, h, i, j} {a, c, g, h, i, j} {a, d
, e, f, g, h} {a, d, e, f, g, i} {a, d, e, f, g, j} {a, d, e, f, h, i} {a, d, e,
 f, h, j} {a, d, e, f, i, j} {a, d, e, g, h, i} {a, d, e, g, h, j} {a, d, e, g,
i, j} {a, d, e, h, i, j} {a, d, f, g, h, i} {a, d, f, g, h, j} {a, d, f, g, i, j
} {a, d, f, h, i, j} {a, d, g, h, i, j} {a, e, f, g, h, i} {a, e, f, g, h, j} {a
, e, f, g, i, j} {a, e, f, h, i, j} {a, e, g, h, i, j} {a, f, g, h, i, j} {b, c,
 d, e, f, g} {b, c, d, e, f, h} {b, c, d, e, f, i} {b, c, d, e, f, j} {b, c, d,
e, g, h} {b, c, d, e, g, i} {b, c, d, e, g, j} {b, c, d, e, h, i} {b, c, d, e, h
, j} {b, c, d, e, i, j} {b, c, d, f, g, h} {b, c, d, f, g, i} {b, c, d, f, g, j}
 {b, c, d, f, h, i} {b, c, d, f, h, j} {b, c, d, f, i, j} {b, c, d, g, h, i} {b,
 c, d, g, h, j} {b, c, d, g, i, j} {b, c, d, h, i, j} {b, c, e, f, g, h} {b, c,
e, f, g, i} {b, c, e, f, g, j} {b, c, e, f, h, i} {b, c, e, f, h, j} {b, c, e, f
, i, j} {b, c, e, g, h, i} {b, c, e, g, h, j} {b, c, e, g, i, j} {b, c, e, h, i,
 j} {b, c, f, g, h, i} {b, c, f, g, h, j} {b, c, f, g, i, j} {b, c, f, h, i, j}
{b, c, g, h, i, j} {b, d, e, f, g, h} {b, d, e, f, g, i} {b, d, e, f, g, j} {b,
d, e, f, h, i} {b, d, e, f, h, j} {b, d, e, f, i, j} {b, d, e, g, h, i} {b, d, e
, g, h, j} {b, d, e, g, i, j} {b, d, e, h, i, j} {b, d, f, g, h, i} {b, d, f, g,
 h, j} {b, d, f, g, i, j} {b, d, f, h, i, j} {b, d, g, h, i, j} {b, e, f, g, h,
i} {b, e, f, g, h, j} {b, e, f, g, i, j} {b, e, f, h, i, j} {b, e, g, h, i, j} {
b, f, g, h, i, j} {c, d, e, f, g, h} {c, d, e, f, g, i} {c, d, e, f, g, j} {c, d
, e, f, h, i} {c, d, e, f, h, j} {c, d, e, f, i, j} {c, d, e, g, h, i} {c, d, e,
 g, h, j} {c, d, e, g, i, j} {c, d, e, h, i, j} {c, d, f, g, h, i} {c, d, f, g,
h, j} {c, d, f, g, i, j} {c, d, f, h, i, j} {c, d, g, h, i, j} {c, e, f, g, h, i
} {c, e, f, g, h, j} {c, e, f, g, i, j} {c, e, f, h, i, j} {c, e, g, h, i, j} {c
, f, g, h, i, j} {d, e, f, g, h, i} {d, e, f, g, h, j} {d, e, f, g, i, j} {d, e,
 f, h, i, j} {d, e, g, h, i, j} {d, f, g, h, i, j} {e, f, g, h, i, j}
{a, b, c, d, e, f, g} {a, b, c, d, e, f, h} {a, b, c, d, e, f, i} {a, b, c, d, e
, f, j} {a, b, c, d, e, g, h} {a, b, c, d, e, g, i} {a, b, c, d, e, g, j} {a, b,
 c, d, e, h, i} {a, b, c, d, e, h, j} {a, b, c, d, e, i, j} {a, b, c, d, f, g, h
} {a, b, c, d, f, g, i} {a, b, c, d, f, g, j} {a, b, c, d, f, h, i} {a, b, c, d,
 f, h, j} {a, b, c, d, f, i, j} {a, b, c, d, g, h, i} {a, b, c, d, g, h, j} {a,
b, c, d, g, i, j} {a, b, c, d, h, i, j} {a, b, c, e, f, g, h} {a, b, c, e, f, g,
 i} {a, b, c, e, f, g, j} {a, b, c, e, f, h, i} {a, b, c, e, f, h, j} {a, b, c,
e, f, i, j} {a, b, c, e, g, h, i} {a, b, c, e, g, h, j} {a, b, c, e, g, i, j} {a
, b, c, e, h, i, j} {a, b, c, f, g, h, i} {a, b, c, f, g, h, j} {a, b, c, f, g,
i, j} {a, b, c, f, h, i, j} {a, b, c, g, h, i, j} {a, b, d, e, f, g, h} {a, b, d
, e, f, g, i} {a, b, d, e, f, g, j} {a, b, d, e, f, h, i} {a, b, d, e, f, h, j}
{a, b, d, e, f, i, j} {a, b, d, e, g, h, i} {a, b, d, e, g, h, j} {a, b, d, e, g
, i, j} {a, b, d, e, h, i, j} {a, b, d, f, g, h, i} {a, b, d, f, g, h, j} {a, b,
 d, f, g, i, j} {a, b, d, f, h, i, j} {a, b, d, g, h, i, j} {a, b, e, f, g, h, i
} {a, b, e, f, g, h, j} {a, b, e, f, g, i, j} {a, b, e, f, h, i, j} {a, b, e, g,
 h, i, j} {a, b, f, g, h, i, j} {a, c, d, e, f, g, h} {a, c, d, e, f, g, i} {a,
c, d, e, f, g, j} {a, c, d, e, f, h, i} {a, c, d, e, f, h, j} {a, c, d, e, f, i,
 j} {a, c, d, e, g, h, i} {a, c, d, e, g, h, j} {a, c, d, e, g, i, j} {a, c, d,
e, h, i, j} {a, c, d, f, g, h, i} {a, c, d, f, g, h, j} {a, c, d, f, g, i, j} {a
, c, d, f, h, i, j} {a, c, d, g, h, i, j} {a, c, e, f, g, h, i} {a, c, e, f, g,
h, j} {a, c, e, f, g, i, j} {a, c, e, f, h, i, j} {a, c, e, g, h, i, j} {a, c, f
, g, h, i, j} {a, d, e, f, g, h, i} {a, d, e, f, g, h, j} {a, d, e, f, g, i, j}
{a, d, e, f, h, i, j} {a, d, e, g, h, i, j} {a, d, f, g, h, i, j} {a, e, f, g, h
, i, j} {b, c, d, e, f, g, h} {b, c, d, e, f, g, i} {b, c, d, e, f, g, j} {b, c,
 d, e, f, h, i} {b, c, d, e, f, h, j} {b, c, d, e, f, i, j} {b, c, d, e, g, h, i
} {b, c, d, e, g, h, j} {b, c, d, e, g, i, j} {b, c, d, e, h, i, j} {b, c, d, f,
 g, h, i} {b, c, d, f, g, h, j} {b, c, d, f, g, i, j} {b, c, d, f, h, i, j} {b,
c, d, g, h, i, j} {b, c, e, f, g, h, i} {b, c, e, f, g, h, j} {b, c, e, f, g, i,
 j} {b, c, e, f, h, i, j} {b, c, e, g, h, i, j} {b, c, f, g, h, i, j} {b, d, e,
f, g, h, i} {b, d, e, f, g, h, j} {b, d, e, f, g, i, j} {b, d, e, f, h, i, j} {b
, d, e, g, h, i, j} {b, d, f, g, h, i, j} {b, e, f, g, h, i, j} {c, d, e, f, g,
h, i} {c, d, e, f, g, h, j} {c, d, e, f, g, i, j} {c, d, e, f, h, i, j} {c, d, e
, g, h, i, j} {c, d, f, g, h, i, j} {c, e, f, g, h, i, j} {d, e, f, g, h, i, j}
{a, b, c, d, e, f, g, h} {a, b, c, d, e, f, g, i} {a, b, c, d, e, f, g, j} {a, b
, c, d, e, f, h, i} {a, b, c, d, e, f, h, j} {a, b, c, d, e, f, i, j} {a, b, c,
d, e, g, h, i} {a, b, c, d, e, g, h, j} {a, b, c, d, e, g, i, j} {a, b, c, d, e,
 h, i, j} {a, b, c, d, f, g, h, i} {a, b, c, d, f, g, h, j} {a, b, c, d, f, g, i
, j} {a, b, c, d, f, h, i, j} {a, b, c, d, g, h, i, j} {a, b, c, e, f, g, h, i}
{a, b, c, e, f, g, h, j} {a, b, c, e, f, g, i, j} {a, b, c, e, f, h, i, j} {a, b
, c, e, g, h, i, j} {a, b, c, f, g, h, i, j} {a, b, d, e, f, g, h, i} {a, b, d,
e, f, g, h, j} {a, b, d, e, f, g, i, j} {a, b, d, e, f, h, i, j} {a, b, d, e, g,
 h, i, j} {a, b, d, f, g, h, i, j} {a, b, e, f, g, h, i, j} {a, c, d, e, f, g, h
, i} {a, c, d, e, f, g, h, j} {a, c, d, e, f, g, i, j} {a, c, d, e, f, h, i, j}
{a, c, d, e, g, h, i, j} {a, c, d, f, g, h, i, j} {a, c, e, f, g, h, i, j} {a, d
, e, f, g, h, i, j} {b, c, d, e, f, g, h, i} {b, c, d, e, f, g, h, j} {b, c, d,
e, f, g, i, j} {b, c, d, e, f, h, i, j} {b, c, d, e, g, h, i, j} {b, c, d, f, g,
 h, i, j} {b, c, e, f, g, h, i, j} {b, d, e, f, g, h, i, j} {c, d, e, f, g, h, i
, j}
{a, b, c, d, e, f, g, h, i} {a, b, c, d, e, f, g, h, j} {a, b, c, d, e, f, g, i,
 j} {a, b, c, d, e, f, h, i, j} {a, b, c, d, e, g, h, i, j} {a, b, c, d, f, g, h
, i, j} {a, b, c, e, f, g, h, i, j} {a, b, d, e, f, g, h, i, j} {a, c, d, e, f,
g, h, i, j} {b, c, d, e, f, g, h, i, j}
{a, b, c, d, e, f, g, h, i, j}

{}
{1} {2} {3} {4} {5}
{1, 2} {1, 3} {1, 4} {1, 5} {2, 3} {2, 4} {2, 5} {3, 4} {3, 5} {4, 5}
{1, 2, 3} {1, 2, 4} {1, 2, 5} {1, 3, 4} {1, 3, 5} {1, 4, 5} {2, 3, 4} {2, 3, 5}
{2, 4, 5} {3, 4, 5}
{1, 2, 3, 4} {1, 2, 3, 5} {1, 2, 4, 5} {1, 3, 4, 5} {2, 3, 4, 5}
{1, 2, 3, 4, 5}
Press any key to continue
 
当然,你可以使用以下的代码:
 char c[10]={'a','b','c','d','e','f','g','h','i','j'};
 char* a=c;
 
替代:
 char* a=new char[10];
 a[0]='a';
 a[1]='b';
 a[2]='c';
 a[3]='d';
 a[4]='e';
 a[5]='f';
 a[6]='g';
 a[7]='h';
 a[8]='i';
 a[9]='j';
 
不过需要注意的是,要消除以下这一行:
delete [] a;
 
因为,不是用new创建的空间,是不能用delete来回收的。
日志 | 阅读 799 次
文章评论,共0条
游客请输入验证码
浏览8953次