SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 314 Weeks Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 13 Dec 2017 My Price 10.00

RedBlackTree rbt = new RedBlackTree(); rbt.insert("D")

The instructions for the program are in the files below. Please do exactly as specified. J unit testing also needed.


  • import static org.junit.Assert.*;

    import org.junit.Test;


    public class RBTTester {

        @Test
        public void test() {
            RedBlackTree rbt = new RedBlackTree();
            rbt.insert("D");
            rbt.insert("B");
            rbt.insert("A");
            rbt.insert("C");
            rbt.insert("F");
            rbt.insert("E");
            rbt.insert("H");
            rbt.insert("G");
            rbt.insert("I");
            rbt.insert("J");
            assertEquals("DBACFEHGIJ", makeString(rbt));
            String str=    
    "Color: 1, Key:D Parent: \n"+
    "Color: 1, Key:B Parent: D\n"+
    "Color: 1, Key:A Parent: B\n"+
    "Color: 1, Key:C Parent: B\n"+
    "Color: 1, Key:F Parent: D\n"+
    "Color: 1, Key:E Parent: F\n"+
    "Color: 0, Key:H Parent: F\n"+
    "Color: 1, Key:G Parent: H\n"+
    "Color: 1, Key:I Parent: H\n"+
    "Color: 0, Key:J Parent: I\n";
            assertEquals(str, makeStringDetails(rbt));
               
        }
       
        public static String makeString(RedBlackTree t)
        {
           class MyVisitor implements RedBlackTree.Visitor {
              String result = "";
              public void visit(RedBlackTree.Node n)
              {
                 result = result + n.key;
              }
           };
           MyVisitor v = new MyVisitor();
           t.preOrderVisit(v);
           return v.result;
        }

        public static String makeStringDetails(RedBlackTree t) {
            {
                   class MyVisitor implements RedBlackTree.Visitor {
                      String result = "";
                      public void visit(RedBlackTree.Node n)
                      {
                          if(!(n.key).equals(""))
                              result = result +"Color: "+n.color+", Key:"+n.key+" Parent: "+n.parent.key+"\n";
                        
                      }
                   };
                   MyVisitor v = new MyVisitor();
                   t.preOrderVisit(v);
                   return v.result;
             }
        }
      // add this in your class 
      //  public static interface Visitor
      //  {
      //      /**
      //     This method is called at each node.
      //     @param n the visited node
      //       */
      //      void visit(Node n);
      //  }
     
     
      // public void preOrderVisit(Visitor v)
      //  {
      //      preOrderVisit(root, v);
      //  }
     
     
      // private static void preOrderVisit(Node n, Visitor v)
      //  {
      //      if (n == null) return;
      //      v.visit(n);
      //      preOrderVisit(n.left, v);
      //      preOrderVisit(n.right, v);
      //  }
       
       
     }
     

Attachments:

Answers

(5)
Status NEW Posted 13 Dec 2017 09:12 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)