Today, I read a book and saw 8.2 recursion problems. I tried the code on the book. I felt that there were still many bugs, so I wrote one myself. The main reason is that the Code in the book is only recursive for recursion, which is not good at recursive return processing. Paste your modified code for future review .. When writing a program, several problems are found. Note: 1. It must be v
Today, I read a book and saw 8.2 recursion problems. I tried the code on the book. I felt that there were still many bugs, so I wrote one myself. The main reason is that the Code in the book is only recursive for recursion, which is not good at recursive return processing. Paste your modified code for future review .. When writing a program, several problems are found. Note: 1. It must be v
Today, I read a book and saw 8.2 recursion problems. I tried the code on the book. I felt that there were still many bugs, so I wrote one myself.
The main reason is that the Code in the book is only recursive for recursion, which is not good at recursive return processing.
Paste your modified code for future review ..
Several problems are found during program writing. Note the following:
1. It must be a vector. ** Printarr = new vector * [Slen]; applies for pointer array initialization. during initialization, the value (* p + I) cannot be used as the left value. Use p [I] instead ..
2. problem Found: Use * (* p + I) = I; to assign a value. Only pointer + offset value can be used for calling. An error occurs when using arrays, for example, * p [I]. the array method can only be used to assign values. I still don't know whether it is a compiler problem. I will stay tuned.
# Include
# Include
# Include
# Include
Using namespace std;
// Create a vector that compares the position of string s in string p.
Void PrintfArrary (char * pstr, char * sstr, vector ** Printarr, int plen, int slen, int pstartnum, int sstartnum)
{
For (int I = sstartnum; I For (int j = pstartnum; j If (* (sstr + I) = * (pstr + j ))
(* Printarr [I]). push_back (j + 1 );
}
// Recursive call to build a sequence.
Void printseq (vector ** Printarr, int slen, vector * Out, int sum ){
If (slen = 0 ){
For (vector : Iterator I (* out). begin (); I! = (* Out). end (); I ++)
Cout <* I;
Cout < }
Else
{
Int I = sum-slen;
If (I ){
For (vector : Iterator j (* printarr [I]). begin (); j! = (* Printarr [I]). end (); j ++ ){
If (* j> * (* out). end ()-1 )){
(* Out). push_back (* j ));
Printseq (printarr, slen-1, out, sum );
(* Out). erase (* out). end ()-1, (* out). end ());
}
}
}
Else
For (vector : Iterator j (* printarr). begin (); j! = (* Printarr). end (); j ++ ){
(* Out). push_back (* j ));
Printseq (printarr, slen-1, out, sum );
(* Out). erase (* out). end ()-1, (* out). end ());
}
}
}
// Initialize and transmit data.
Void ConnectSequence (char * pstr, char * sstr)
{
Int plen = strlen (pstr );
Int slen = strlen (sstr );
Vector ** Printarr = new vector * [Slen];
For (int I = 0; I
Printarr [I] = new vector ;
}
Vector * Out = new vector ;
PrintfArrary (pstr, sstr, printarr, plen, slen, 0, 0 );
Printseq (printarr, slen, out, slen );
}
Int main (){
Char * a = "abdbccab ";
Char * B = "abc ";
ConnectSequence (a, B );
Return 0;
}