DAG based application
the other day I could not exprese myself correctly and get closed my answer, so here's my second shot:
I need to create a basic DAG (Directed Acyclic Graph) application, put on common words, a node based application. I don't need a GUI for nw, just a console example, that excecute the whole tree.
here's what I have so far :
typedef struct Node
{
int type;
void ( *excecute)(); //the callback function
struct Node *ins;
struct Node *outs;
}
//some functions
void root(float n,float *buffer)
{
buffer[0]=sqrtf(n);
}
void sum(float a, float b, float *buffer)
{
buffer[0]=a+b;
}
void Output_screen(float val)
{
printf(""The DAG output is: %f ", val);
}
The nodes could have any number of inputs and any umber of outputs (how do i handle them?)
My question is: How do I const开发者_如何学JAVAruct a DAG with the output of a node sum be the input of a node root and that output be the input of the node Output_screen?
Node(sum)---> Node(root)--->Node(Output_screen)
I will preciate any help, since I could'nt find any tut on it
What you need is a copy of Knuth. I cannot recommend strongly enough reading him to learn about this kind of basic data structure.
Aside from which, you could use linked lists to represent the node lists. If you are in C++, you can also use STL vectors of pointers.
精彩评论