C ++ 归 集

xiaoxiao2021-03-06  16

Take the collection {a, s, d, f} as an example of recursive thinking

Step 1: Remove F, and don't drop F, get two sets {A, S, D, F}, {A, S, D}

Step 2: Two collections that will get, remove D, and do not remove D, get 4 collection

>>>>>>

In order to do it, after removing the first element, you get all the subsets.

The program is implemented as follows:

#include #include void build (char str [], int N); void main () {char string [5] = "asdf"; // instance collection is placed in array Build (string, 4);} void build (char str [], int N) {if (n == 0) // control output {cout << str; cout << endl;} else {build (Str, N- 1); CHAR newsTR [5] = ''; // Remove the element of this position into empty STRCAT (NEWSTR, STR); newstr [n-1] = ''; build (newstr, n-1); }

转载请注明原文地址:https://www.9cbs.com/read-44875.html

New Post(0)