Hi, this is actually for a homework project, so I'm looking for some guidance. I need to write a function that will take in an array and split the function, rearranging the array by putting any elements < splitter before the splitter string and elements > splitter after it. The arguments must remain the way they are. The function works for the most part, except when the splitter string appears more than once in the array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
string f[6] = { "grant", "buster", "kari", "tory", "adam", "jamie" };
int r = split(f, 6, "jessi"); // returns 4
// f might now be
// "grant" "buster" "jamie" "adam" "tory" "kari"
// or "jamie" "adam" "buster" "grant" "kari" "tory"
// or one of several other orderings.
// The first 4 elements are < "jessi"; the last 2 aren't.
string g[4] = { "jamie", "adam", "buster", "narrator" };
int s = split(g, 4, "buster"); // returns 1
// g must now be either
// "adam" "buster" "narrator" "jamie"
// or "adam" "buster" "jamie" "narrator"
// All elements < "buster" (i.e., "adam") come before all others.
// All elements > "buster" (i.e., "jamie" and "narrator") come
// after all others.