Documentation ¶
Overview ¶
Example ¶
package main import ( "bufio" "fmt" "os" "github.com/danos/utils/tsort" ) func main() { var e error f := os.Stdin n := os.Args[0] if len(os.Args) > 1 { fname := os.Args[1] f, e = os.Open(fname) if e != nil { fmt.Fprintf(os.Stderr, "%s: %s\n", n, e) os.Exit(1) } } g := tsort.New() scanner := bufio.NewScanner(bufio.NewReader(f)) scanner.Split(bufio.ScanWords) var v, w string elems := make([]string, 0) for scanner.Scan() { t := scanner.Text() elems = append(elems, t) } if len(elems)%2 != 0 { fmt.Fprintf(os.Stderr, "%s: odd data count\n", n) os.Exit(1) } for i := 0; i < len(elems); i++ { v = elems[i] i += 1 w = elems[i] g.AddEdge(v, w) } out, err := g.Sort() if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } for _, s := range out { fmt.Println(s) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.