Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
typedef struct node_s
{
int value;
struct node_s *nextSibling;
struct node_s *firstChild;
} node_t;
type 'a Tree = {
value: 'a;
children: 'a tree list;
}
struct Node(T){
Node[] children;
T data;
}
alias TreeOfIntegers = Node!(int);
class Node<T> {
final T value;
final List<Node<T>> children;
Node(this.value, this.children);
}
-record( node,{
value :: any(),
children = [] :: [node#{}]
}).
type node_t
integer:: value
type(node_t), pointer :: next_sibling;
type(node_t), pointer :: first_child;
end type node_t
type Tree struct {
Key keyType
Deco valueType
Children []*Tree
}
type Tree[L any] struct {
Label L
Children []*Tree[L]
}
import Data.List
data Matrix a = Matrix [[a]]
deriving (Eq)
-- переопрееляем вывод для матриц
instance Show a => Show (Matrix a)
where
show (Matrix a) = intercalate "\n" (map (intercalate " " . map show) a)
-- сложение
plus :: Num a => [[a]] -> [[a]] -> [[a]]
plus a b = zipWith (zipWith (+)) a b
-- instance (+) a => (+) (Matrix a) (Matrix a)
-- where
-- (+) (Matrix a) (Matrix b) = plus_mat (Matrix a) (Matrix b)
-- | Identity matr
class Node {
constructor (value, children = []) {
this.value = value
this.children = children
}
}
local function Tree(v, c)
return {
val = v,
children = c
}
end
@interface Node:NSObject
@property id value; // id means any object value
@property NSMutableArray *children;
@end
// usage like
Node *n=[Node new];
n.value=@1;
[n.children addObject:otherNode];
[n.children removeLastObject];
// somewhere needed also
@implementation Node
-(instancetype)init {
if (!(self=[super init])) return nil;
_children=[NSMutableArray array];
return self;
}
@end
class Tree
{
public $children = [];
public $data;
public function __construct($data, $children)
{
$this->data = $data;
$this->children = $children;
}
}
final class Node {
public function __construct(public array $children, public mixed $data) {}
}
type
generic
TTree<_T> = class(TObject)
Children: array of TObject;
Data: _T;
end;
type
TStringTree = specialize TTree<String>;
type
TTree = class
Children: array of TTree;
Data: TObject;
end;
my $tree = {
'Root' => {
'Child1' => {
'GrandChild1' => {},
'GrandChild2' => {}
},
'Child2' => {}
}
};
class Node:
def __init__(self, value, *children):
self.value = value
self.children = list(children)
Node = Struct.new(:children)
parent = Node.new([])
parent.children << Node.new([])
struct Node<T> {
value: T,
children: Vec<Node<T>>,
}
case class Node[T](value: T, children: List[Node[T]] = Nil)
(define (make-tree value children)
(cons value children))
(define (tree-value t) (car t))
(define (tree-first-child t) (cadr t))
(define (tree-rest-children t) (cddr t))