Coder Social home page Coder Social logo

graphtree.h's Introduction

graphtree.h

[CC0] Header-only c library to visualize DFS(depth-first search) easily with graphviz!

License CC0 by https://github.com/toduq

HOW TO USE

Just include graphtree.h.

BEFORE

Labeling BEFORE children node search.

#include "graphtree.h"
void before_labeling() {
  graphtree_t graph;
  graphtree_init(&graph, "before.dot");

  graphtree_down(&graph, "parent");
  graphtree_down(&graph, "child");
  graphtree_down(&graph, "grandchild");
  graphtree_up(&graph);
  graphtree_down(&graph, "grandchild2");
  graphtree_up(&graph);
  graphtree_up(&graph);
  graphtree_down(&graph, "child2");
  
  graphtree_save(&graph);
}

Execute dot -T png before.dot -o before.png

/before.png

AFTER

Labeling AFTER children node search.

#include "graphtree.h"
int after_labeling_search(graphtree_t *graph, int depth) {
  graphtree_enter(graph);
  if(depth==0) {
    int score = rand() % 20;
    graphtree_exit(graph, "%d", score);
    return score;
  } else {
    int max = -1;
    for(int i=0; i<3; i++) {
      int score = after_labeling_search(graph, depth-1);
      if(score > max) max = score;
    }
    graphtree_exit(graph, "%d", max);
    return max;
  }
}

int after_labeling() {
  srand((unsigned)time(NULL));
  graphtree_t graph;
  graphtree_init(&graph, "after.dot");
  after_labeling_search(&graph, 2);
  graphtree_save(&graph);
}

Execute dot -T png after.dot -o after.png

/after.png

Actual code is here /sample.c

graphtree.h's People

Contributors

toduq avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.