b'\n_START_ARTICLE_\nAlbero n-ario\n_START_SECTION_\nImplementazione primo figlio-fratello\n_START_PARAGRAPH_\nEcco il codice sorgente  Java di una implementazione con visitepreorder e postorder:_NEWLINE_  _NEWLINE_class NTreeNode<E> //implementazione nodo albero con tipo generico E{ _NEWLINE_protected NTreeNode firstChild; //primo figlio_NEWLINE_protected NTreeNode sibling; //fratello_NEWLINE_protected E element; //elemento del nodo_NEWLINE_public NTreeNode() //costruttore_NEWLINE_{_NEWLINE_this(null,null, null);_NEWLINE_}_NEWLINE_public NTreeNode(E element, NTreeNode firstChild)_NEWLINE_{_NEWLINE_this(element, firstChild,null);_NEWLINE_}_NEWLINE_public NTreeNode(E element, NTreeNode firstChild, NTreeNode sibling)_NEWLINE_{_NEWLINE_this.element=element;_NEWLINE_this.firstSon=firstChild;_NEWLINE_this.sibling=sibling;_NEWLINE_}_NEWLINE_public String toString(){_NEWLINE_return (String) element;_NEWLINE_}}public class NTree //classe pubblica albero{_NEWLINE_protected NTreeNode root; //radice dell\'albero_NEWLINE_protected int size; //variabile per la grandezza dell\'albero_NEWLINE_public NTree() //costruttore_NEWLINE_{_NEWLINE_root=null;_NEWLINE_size=0;_NEWLINE_}_NEWLINE_public boolean insert(NTreeNode parent, NTreeNode[] children) //metodo per l\'inserimento_NEWLINE_{_NEWLINE_if(this.search(parent) && children.length!=0)_NEWLINE_{_NEWLINE_NTreeNode temp=this.searchNode(parent);_NEWLINE_                        temp.firstChild = children[0];_NEWLINE_for(int i=1; i < children.length; i++)_NEWLINE_temp=temp.sibling = children[i];_NEWLINE_                        return true;_NEWLINE_}_NEWLINE_else_NEWLINE_System.out.println("Errore, nodo inesistente. Impossibile inserire i nodi dei figli");_NEWLINE_//stampa errore_NEWLINE_                return false;_NEWLINE_}_NEWLINE_public boolean search(NTreeNode node) //metodo per la ricerca di un nodo_NEWLINE_{_NEWLINE_NTreeNode p=this.root;_NEWLINE_if(p!=null){_NEWLINE_if(p==node) return true;_NEWLINE_else_NEWLINE_{_NEWLINE_NTreeNode t=p.firstChild;_NEWLINE_while(t!=null)_NEWLINE_{_NEWLINE_search(t);_NEWLINE_t = t.sibling;_NEWLINE_}_NEWLINE_}_NEWLINE_}_NEWLINE_return false;_NEWLINE_}_NEWLINE_public TNodeList searchNode(TNodeList node)_NEWLINE_{_NEWLINE_TNodeList p=this.root;_NEWLINE_if(p!=null){_NEWLINE_if(p==node) return p;_NEWLINE_else_NEWLINE_{_NEWLINE_TNodeList t=p.children.head;_NEWLINE_while(t!=null)_NEWLINE_{_NEWLINE_search(t);_NEWLINE_t=t.next;_NEWLINE_}_NEWLINE_}_NEWLINE_}_NEWLINE_return null;_NEWLINE_}_NEWLINE_public void preorder(){_NEWLINE_preorder(root);_NEWLINE_}_NEWLINE_public void preorder(NTreeNode p){_NEWLINE_if(p!=null){_NEWLINE_System.out.println(p.toString());_NEWLINE_NTreeNode t=p.firstChild;_NEWLINE_while(t!=null){_NEWLINE_preorder(t);_NEWLINE_t = t.sibling;_NEWLINE_}_NEWLINE_}_NEWLINE_}_NEWLINE_public void postorder(){_NEWLINE_postorder(root);_NEWLINE_}_NEWLINE_public void postorder(NTreeNode p){_NEWLINE_if(p!=null){_NEWLINE_NTreeNode t=p.firstChild;_NEWLINE_while(t!=null){_NEWLINE_postorder(t);_NEWLINE_t = t.sibling;_NEWLINE_}_NEWLINE_System.out.println(p.toString());_NEWLINE_        }_NEWLINE_}}\n_START_SECTION_\nImplementazione con lista collegata\n_START_PARAGRAPH_\nDi seguito, un\'altra implementazione di alberi n-ari molto diffusa, stavolta sfruttando delle liste concatenate. Il linguaggio di programmazione scelto per questa implementazione \xc3\xa8 il Java._NEWLINE_class TNodeList<E>{_NEWLINE_public E element;_NEWLINE_public TNodeList next;_NEWLINE_public LinkedList children;_NEWLINE_public TNodeList(E element)_NEWLINE_{_NEWLINE_children=new LinkedList();_NEWLINE_this.element=element;_NEWLINE_}_NEWLINE_public String toString()_NEWLINE_{_NEWLINE_return (String)this.element;_NEWLINE_}}class  LinkedList{_NEWLINE_TNodeList head, tail;_NEWLINE_int size;_NEWLINE_public LinkedList(){_NEWLINE_head=tail=null;_NEWLINE_size=0;_NEWLINE_}_NEWLINE_public void addFirst(TNodeList node)_NEWLINE_{_NEWLINE_if(head==null){_NEWLINE_head=tail=node;_NEWLINE_}_NEWLINE_else_NEWLINE_{_NEWLINE_node.next=head;_NEWLINE_head=node;_NEWLINE_}_NEWLINE_size++;_NEWLINE_}_NEWLINE_public void addLast(TNodeList node)_NEWLINE_{_NEWLINE_if(tail==null)_NEWLINE_{_NEWLINE_head=tail=node;_NEWLINE_}_NEWLINE_else_NEWLINE_{_NEWLINE_tail.next=node;_NEWLINE_tail=node;_NEWLINE_}_NEWLINE_size++;_NEWLINE_}}public class NTL{_NEWLINE_public TNodeList root;_NEWLINE_public int size;_NEWLINE_public NTL(TNodeList root)_NEWLINE_{_NEWLINE_this.root=root;_NEWLINE_size=0;_NEWLINE_}_NEWLINE_public boolean insert(TNodeList[] children, TNodeList parent)_NEWLINE_{_NEWLINE_if(this.search(parent))_NEWLINE_{_NEWLINE_TNodeList tmp=this.searchNode(parent); _NEWLINE_if(children.length!=0)_NEWLINE_{_NEWLINE_for(int i=0; i<children.length; i++)_NEWLINE_{_NEWLINE_parent.children.addLast(children[i]);_NEWLINE_}_NEWLINE_return true;_NEWLINE_}_NEWLINE_else _NEWLINE_{_NEWLINE_System.out.println("Nessun figlio da inserire");_NEWLINE_return false;_NEWLINE_}_NEWLINE_}_NEWLINE_System.out.println("Nodo genitore inesistente");_NEWLINE_return false;_NEWLINE_}_NEWLINE_public boolean search(TNodeList node)_NEWLINE_{_NEWLINE_if(size!=0)_NEWLINE_{_NEWLINE_TNodeList p=this.root;_NEWLINE_if(p!=null)_NEWLINE_{_NEWLINE_if(p==node) return true;_NEWLINE_else_NEWLINE_{_NEWLINE_TNodeList t = p.children.head;_NEWLINE_while(t!=null)_NEWLINE_{_NEWLINE_search(t);_NEWLINE_t=t.next;_NEWLINE_}_NEWLINE_}_NEWLINE_}_NEWLINE_}_NEWLINE_return false;_NEWLINE_}_NEWLINE_public TNodeList searchNode(TNodeList node)_NEWLINE_{_NEWLINE_TNodeList p=this.root;_NEWLINE_if(p!=null){_NEWLINE_if(p==node) return p;_NEWLINE_else_NEWLINE_{_NEWLINE_TNodeList t = p.children.head;_NEWLINE_while(t!=null)_NEWLINE_{_NEWLINE_search(t);_NEWLINE_t=t.next;_NEWLINE_}_NEWLINE_}_NEWLINE_}_NEWLINE_return null;_NEWLINE_}_NEWLINE_        public void preorder(){_NEWLINE_preorder(root);_NEWLINE_}_NEWLINE_public void preorder(TNodeList p){_NEWLINE_if(p!=null){_NEWLINE_System.out.println(p.toString());_NEWLINE_TNodeList t = p.children.head;_NEWLINE_while(t!=null){_NEWLINE_preorder(t);_NEWLINE_t=t.next;_NEWLINE_}_NEWLINE_}_NEWLINE_}_NEWLINE_public void postorder(){_NEWLINE_postorder(root);_NEWLINE_}_NEWLINE_public void postorder(TNodeList p){_NEWLINE_if(p!=null){_NEWLINE_TNodeList t = p.children.head;_NEWLINE_while(t!=null){_NEWLINE_postorder(t);_NEWLINE_t=t.next;_NEWLINE_}_NEWLINE_System.out.println(p.toString());_NEWLINE_        }}'