Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,36 @@
with Ada.Text_IO, Ada.Directories;
procedure Directory_Tree is
procedure Print_Tree(Current: String; Indention: Natural := 0) is
function Spaces(N: Natural) return String is
(if N= 0 then "" else " " & Spaces(N-1));
use Ada.Directories;
Search: Search_Type;
Found: Directory_Entry_Type;
begin
Start_Search(Search, Current, "");
while More_Entries(Search) loop
Get_Next_Entry(Search, Found);
declare
Name: String := Simple_Name(Found);
Dir: Boolean := Kind(Found) = Directory;
begin
if Name(Name'First) /= '.' then
-- skip all files who's names start with ".", namely "." and ".."
Ada.Text_IO.Put_Line(Spaces(2*Indention) & Simple_Name(Found)
& (if Dir then " (dir)" else ""));
if Dir then
Print_Tree(Full_Name(Found), Indention + 1);
end if;
end if;
end;
end loop;
end Print_Tree;
begin
Print_Tree(Ada.Directories.Current_Directory);
end Directory_Tree;

View file

@ -2,7 +2,7 @@ import std.stdio, std.conv, std.algorithm, std.array;
struct Node(T) { T value; Node* left, right; }
string[] treeIndent(T)(in Node!T* t) {
string[] treeIndent(T)(in Node!T* t) pure nothrow @safe {
if (!t) return ["-- (null)"];
const tr = t.right.treeIndent;
return "--" ~ t.value.text ~

View file

@ -0,0 +1,31 @@
package main
import (
"log"
"os"
"github.com/BurntSushi/toml"
)
type Node struct {
Name string
Children []*Node
}
func main() {
tree := &Node{"root", []*Node{
&Node{"a", []*Node{
&Node{"d", nil},
&Node{"e", []*Node{
&Node{"f", nil},
}}}},
&Node{"b", nil},
&Node{"c", nil},
}}
enc := toml.NewEncoder(os.Stdout)
enc.Indent = " "
err := enc.Encode(tree)
if err != nil {
log.Fatal(err)
}
}

View file

@ -0,0 +1,79 @@
public class VisualizeTree {
public static void main(String[] args) {
BinarySearchTree tree = new BinarySearchTree();
tree.insert(100);
for (int i = 0; i < 20; i++)
tree.insert((int) (Math.random() * 200));
tree.display();
}
}
class BinarySearchTree {
private Node root;
private class Node {
private int key;
private Node left, right;
Node(int k) {
key = k;
}
}
public boolean insert(int key) {
if (root == null)
root = new Node(key);
else {
Node n = root;
Node parent;
while (true) {
if (n.key == key)
return false;
parent = n;
boolean goLeft = key < n.key;
n = goLeft ? n.left : n.right;
if (n == null) {
if (goLeft) {
parent.left = new Node(key);
} else {
parent.right = new Node(key);
}
break;
}
}
}
return true;
}
public void display() {
final int height = 5, width = 64;
int len = width * height * 2 + 2;
StringBuilder sb = new StringBuilder(len);
for (int i = 1; i <= len; i++)
sb.append(i < len - 2 && i % width == 0 ? "\n" : ' ');
displayR(sb, width / 2, 1, width / 4, width, root, " ");
System.out.println(sb);
}
private void displayR(StringBuilder sb, int c, int r, int d, int w, Node n,
String edge) {
if (n != null) {
displayR(sb, c - d, r + 2, d / 2, w, n.left, " /");
String s = String.valueOf(n.key);
int idx1 = r * w + c - (s.length() + 1) / 2;
int idx2 = idx1 + s.length();
int idx3 = idx1 - w;
if (idx2 < sb.length())
sb.replace(idx1, idx2, s).replace(idx3, idx3 + 2, edge);
displayR(sb, c + d, r + 2, d / 2, w, n.right, "\\ ");
}
}
}

View file

@ -0,0 +1,71 @@
/* REXX ***************************************************************
* 10.05.2014 Walter Pachl using the tree and the output format of C
**********************************************************************/
Call mktree
Say node.1.0name
Call tt 1,''
Exit
tt: Procedure Expose node.
/**********************************************************************
* show a subtree (recursively)
**********************************************************************/
Parse Arg k,st
Do i=1 To node.k.0
If i=node.k.0 Then
s='`--'
Else
s='|--'
c=node.k.i
If st<>'' Then
st=left(st,length(st)-2)' '
st=repl(st,' ','` ')
Say st||s||node.c.0name
Call tt c,st||s
End
Return
Exit
mktree: Procedure Expose node. root
/**********************************************************************
* build the tree according to the task
**********************************************************************/
node.=0
r=mknode('R');
a=mknode('A'); Call attchild a,r
b=mknode('B'); Call attchild b,a
c=mknode('C'); Call attchild c,a
d=mknode('D'); Call attchild d,b
e=mknode('E'); Call attchild e,b
f=mknode('F'); Call attchild f,b
g=mknode('G'); Call attchild g,b
h=mknode('H'); Call attchild h,d
i=mknode('I'); Call attchild i,h
j=mknode('J'); Call attchild j,i
k=mknode('K'); Call attchild k,j
l=mknode('L'); Call attchild l,j
m=mknode('M'); Call attchild m,e
n=mknode('N'); Call attchild n,e
Return
mknode: Procedure Expose node.
/**********************************************************************
* create a new node
**********************************************************************/
Parse Arg name
z=node.0+1
node.z.0name=name
node.0=z
Return z /* number of the node just created */
attchild: Procedure Expose node.
/**********************************************************************
* make a the next child of father
**********************************************************************/
Parse Arg a,father
node.a.0father=father
z=node.father.0+1
node.father.z=a
node.father.0=z
node.a.0level=node.father.0level+1
Return

View file

@ -0,0 +1 @@
root = BinaryTreeNode.from_array [1, [2, [4, 7], [5]], [3, [6, [8], [9]]]]

View file

@ -0,0 +1,2 @@
require 'pp'
pp root