Same fringe: Difference between revisions

Updated both D entries
(Updated both D entries)
Line 451:
T[] scan(Node!T* t) {
if (!t) return [];
ifreturn (!t.left && !t.right) ? [t.data] :
return [ scan(t.left) ~ scan(t.data]right);
else
return scan(t.left) ~ scan(t.right);
}
return scan(t1) == scan(t2);
Line 460 ⟶ 458:
 
void main() {
Node!int*alias n(intN x, Node!int* l=null, Node!int* r=null) {;
auto t1 = new autoN(10, nnew =N(20, new N(30, new N(40), new Node!intN(50))));
auto t2 = new *nN(1, =new Node!intN(x2, lnew N(3, rnew N(40), new N(50))));
auto t3 = nnew N(1, nnew N(2, nnew N(3, nnew N(40), nnew N(51))));
return n;
}
 
auto t1 = n(10, n(20, n(30, n(40), n(50))));
auto t2 = n(1, n(2, n(3, n(40), n(50))));
auto t3 = n(1, n(2, n(3, n(40), n(51))));
writeln(sameFringe(t1, t2));
writeln(sameFringe(t1, t3));
Line 513 ⟶ 506:
T data;
BinaryTreeNode* left, right;
 
this(T x, BinaryTreeNode* l=null, BinaryTreeNode* r=null)
pure nothrow {
this.data = x;
this.left = l;
this.right = r;
}
}
 
Line 660 ⟶ 646:
void main() {
import std.stdio;
alias N = BinaryTreeNode!int N;
 
static N* n(in int x, N* l=null, N* r=null) pure nothrow {