import'dart:io';import'dart:collection';classNode{intiData;doubledData;NodeleftChild;NoderightChild;voiddisplayNode(){stdout.write('{');stdout.write(iData);stdout.write(', ');stdout.write(dData);stdout.write('}');}}classTree{Noderoot;Tree(){root=null;}Nodefind(intkey){Nodecurrent=root;while(current.iData!=key){if(key<current.iData){current=current.leftChild;}else{current=current.rightChild;}if(current==null){returnnull;}}returncurrent;}voidinsert(intkey,doubledd){NodenewNode=newNode();newNode.iData=key;newNode.dData=dd;if(root==null){root=newNode;}else{Nodecurrent=root;Nodeparent;while(true){parent=current;if(key<current.iData){current=current.leftChild;if(current==null){parent.leftChild=newNode;return;}}else{current=current.rightChild;if(current==null){parent.rightChild=newNode;return;}}}}}Nodeminimum(){Nodecurrent=root;Nodelast;while(current!=null){last=current;current=current.leftChild;}returnlast;}booldelete(intkey){Nodecurrent=root;Nodeparent=root;boolisLeftChild=true;while(current.iData!=key){parent=current;if(key<current.iData){isLeftChild=true;current=current.leftChild;}else{isLeftChild=false;current=current.rightChild;}if(current==null){returnfalse;}if(current.leftChild==null&¤t.rightChild==null){if(current==root){root=null;}elseif(isLeftChild){parent.leftChild=null;}else{parent.rightChild=null;}}elseif(current.rightChild==null){if(current==root){root=current.leftChild;}elseif(isLeftChild){parent.leftChild=current.leftChild;}else{parent.rightChild=current.leftChild;}}elseif(current.leftChild==null){if(current==root){root=current.rightChild;}elseif(isLeftChild){parent.leftChild=current.rightChild;}else{parent.rightChild=current.rightChild;}}else{Nodesuccessor=getSuccessor(current);if(current==root){root=successor;}elseif(isLeftChild){parent.leftChild=successor;}else{parent.rightChild=successor;// successor.leftChild = current.leftChild;}}}returntrue;}NodegetSuccessor(NodedelNode){NodesuccessorParent=delNode;Nodesuccessor=delNode;Nodecurrent=delNode.rightChild;while(current!=null){successorParent=successor;successor=current;current=current.leftChild;}if(successor!=delNode.rightChild){successorParent.leftChild=successor.rightChild;successor.rightChild=delNode.rightChild;}returnsuccessor;}voidtraverse(inttraverseType){switch(traverseType){case1:stdout.write('Preorder traveral: ');preOrder(root);break;case2:stdout.write('Inorder traveral: ');inOrder(root);break;case3:stdout.write('Postorder traveral: ');postOrder(root);break;}stdout.writeln();}voidpreOrder(NodelocalRoot){if(localRoot!=null){stdout.write('${localRoot.iData} ');preOrder(localRoot.leftChild);preOrder(localRoot.rightChild);}}voidinOrder(NodelocalRoot){if(localRoot!=null){inOrder(localRoot.leftChild);stdout.write('${localRoot.iData} ');inOrder(localRoot.rightChild);}}voidpostOrder(NodelocalRoot){if(localRoot!=null){postOrder(localRoot.leftChild);postOrder(localRoot.rightChild);stdout.write('${localRoot.iData} ');}}voiddisplayTree(){Queue<Node>globalQueue=newQueue<Node>();globalQueue.addLast(root);intnBlanks=32;boolisRowEmpty=false;stdout.writeln(".............................................");while(isRowEmpty==false){Queue<Node>localQueue=newQueue<Node>();isRowEmpty=true;for(inti=0;i<nBlanks;i++){stdout.write(' ');}while(globalQueue.isEmpty==false){Nodetemp=globalQueue.removeLast();if(temp!=null){stdout.write(temp.iData);localQueue.addLast(temp.leftChild);localQueue.addLast(temp.rightChild);if(temp.leftChild!=null||temp.rightChild!=null){isRowEmpty=false;}}else{stdout.write('--');localQueue.addLast(null);localQueue.addLast(null);}for(inti=0;i<nBlanks*2-2;i++){stdout.write(' ');}}stdout.writeln();nBlanks=nBlanks~/2;while(localQueue.isEmpty==false){globalQueue.addLast(localQueue.removeLast());}}stdout.writeln(".............................................");}}voidmain(List<String>args){Treetree=newTree();tree.insert(50,1.5);tree.insert(25,1.7);tree.insert(75,1.9);tree.insert(12,1.5);tree.insert(37,1.2);tree.insert(43,1.7);tree.insert(30,1.5);tree.insert(33,1.2);tree.insert(87,1.7);tree.insert(93,1.5);tree.insert(97,1.5);while(true){stdout.write('Enter first letter of show, insert, find, delete, traverse: ');Stringchoise=stdin.readLineSync();switch(choise){case's':tree.displayTree();break;case'i':stdout.write('Enter value to insert: ');intvalue=int.parse(stdin.readLineSync());tree.insert(value,value+0.9);break;case'f':stdout.write('Enter value to find: ');intvalue=int.parse(stdin.readLineSync());Nodefound=tree.find(value);if(found!=null){stdout.write('Found: ');found.displayNode();stdout.writeln();}else{stdout.write('Value not Found');}break;case'd':stdout.write('Enter value to delete: ');intvalue=int.parse(stdin.readLineSync());boolisDeleted=tree.delete(value);if(isDeleted){tree.displayTree();}else{stdout.write('Value not Found');}break;case't':stdout.write('Please write type of traverse; Pre Order - 1, In Order - 2, Post Order - 3: ');intvalue=int.parse(stdin.readLineSync());tree.traverse(value);break;}}}