覺得自己的程序寫的太蠢,求指點。
竟然用到了set和遞歸,肯定內存占用很大,
求改進指點。謝謝。
// test102.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
using namespace std;
void DoCombine(set &mystrset, string mystr)
{
if (mystr.length()==0) return;
mystrset.insert(mystr);
for (int i=0; i
{
string tmp=mystr;
tmp.erase(i, 1);
DoCombine(mystrset, tmp);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
set mystrset;
DoCombine(mystrset, "abcd");
for (set::iterator it=mystrset.begin(); it!=mystrset.end(); ++it)
cout << *it << endl;
getchar();
return 0;
}
竟然用到了set和遞歸,肯定內存占用很大,
求改進指點。謝謝。
// test102.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
using namespace std;
void DoCombine(set
{
if (mystr.length()==0) return;
mystrset.insert(mystr);
for (int i=0; i
string tmp=mystr;
tmp.erase(i, 1);
DoCombine(mystrset, tmp);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
set
DoCombine(mystrset, "abcd");
for (set
cout << *it << endl;
getchar();
return 0;
}