Hi,
I have a problem with L-systems recursion, I tried a lot of ways to figure out how to make my fuction recure but I have no luck at all.
What the program must do is the Koch system or rather the replacement rule, where by everytime the fuction recurs, every instance of "F" is replaced with "F+F-F-F+F" (F being the axiom)
This is coding which I came with so far but still working on other ways to solve the problem. My mind is blocked right now.
Option A:
//This code gives me an error over and over again
void RecursionProblem(char* c)
{
char axiom = 'F';
char rule[] = {"F+F-F-F+F"};
int length = sizeof(rule);
c = new char[length];
for(int i = 0; i < length; i++)
{
if(c[i] == axiom)
{
cout << c[i];
}
}
delete[] c;
}
Opyion 2:
//This was my test on how to map F --> F+F-F-F+F
int main()
{
char* str[1];
char rule[] = {"F+F-F-F+F"};
int length = sizeof(rule);
str[1] = new char[length];
str[1][1] = 'F';
if (str[1][1] == 'F')
{
str[1] = rule;
}
cout << str[1];
delete[] *str;
return 0;
}
Are there any suggestions as to how I can maybe tackle this problem?