views:

54

answers:

1

Hi

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 construct 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

A: 

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.

bmargulies
Hi , thanks a lot for your answer, though what is Knuth?if it is a book, could you provide me the full name to google for it? Also, I have to stick with C , not C++ thank
Raul
bmargulies
Thanks a lot! Is a very interesting and a must have book... but still I'm in a need for an answer...How could I trigger the excecution of the node tree?
Raul
you call execute on the top node and it recurses onto the children?
bmargulies
but execute is dynamically assigned during each node creation to one of the two functions: sum and root and each of them have different parametters.... so how i evaluate them in a generic way? thanks in advance
Raul