File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ function Tree ( data ) {
4+ this . count = 1 ;
5+ this . root = new Node ( null , data ) ;
6+ this . root . tree = this ;
7+ }
8+
9+ function Node ( parent , data ) {
10+ this . data = data ;
11+ this . parent = parent ;
12+ this . count = 0 ;
13+ if ( parent ) {
14+ this . tree = parent . tree ;
15+ this . tree . count ++ ;
16+ if ( parent . count < 1 ) {
17+ parent . first = this ;
18+ }
19+ if ( parent . last ) {
20+ parent . last . next = this ;
21+ this . prev = parent . last ;
22+ }
23+ parent . last = this ;
24+ parent . count ++ ;
25+ }
26+ this . prev = null ;
27+ this . next = null ;
28+ this . first = null ;
29+ this . last = null ;
30+ }
31+
32+ let tree = new Tree ( { name : 'root' } ) ;
33+ let n1 = new Node ( tree . root , { name : 'n1' } ) ;
34+ let n2 = new Node ( tree . root , { name : 'n2' } ) ;
35+ let n3 = new Node ( tree . root , { name : 'n3' } ) ;
36+
37+ console . dir ( tree , { depth : null } ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ function Node ( parent , name ) {
4+ this . name = name ;
5+ if ( parent ) {
6+ this . parent = parent ;
7+ parent [ name ] = this ;
8+ }
9+ }
10+
11+ let root = new Node ( null , 'root' ) ;
12+ let n1 = new Node ( root , 'n1' ) ;
13+ let n2 = new Node ( root , 'n2' ) ;
14+ let n3 = new Node ( root , 'n3' ) ;
15+
16+ console . dir ( root , { depth : null } ) ;
You can’t perform that action at this time.
0 commit comments