I am attempting to create a linked list that will keep track of which order I want to use certain functions. I've have around 20 functions that all execute in a couple areas of my code, but the order in which they execute are dynamic, so I was looking at creating a list where I insert which function would be executed at a certain time to clean up the code to only have one area for all the if checks, and another area to do the functions. This makes it look efficient and easy to use. Problem I have is when I want to pass in variables. Take a look at the pseudo code in C...
void func1() { ... }
void func2() { ... }
void func3(x,y) {...}
void func4(z) {...}
void func5() {...}
// Do some If checks to determine order
addFuncToList( func3 );
addFuncToList( func5 );
addFuncToList( func1 );
while(condition) {
x++;
y--;
execute_funcs( currentNode );
currentNode = myList->next;
}
// Do some If checks to determine order
addFuncToList( func1 );
addFuncToList( func5 );
addFuncToList( func2 );
while(condition2) {
execute_funcs( currentNode );
currentNode = myList->next;
}
void execute_funcs( currentNode ) {
if( currentNode == 1 ) func1();
if( currentNode == 2 ) func2();
if( currentNode == 3 ) func3();
...
}
So I like this approach, but I don't want to make a bunch of global variables, I'd like to be able to pass in variables into most of these functions. Most functions need no variables passed in but some need different types passed in. Any ideas?