Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1.     public static Node problem0(Node rootNode) {//method for your "problem0" which is going to deal with "rootnode"
  2.         Node last = rootNode; //setting "next" local variable to "rootnode"
  3.         double data = rootNode.getdata(); //setting "data" variable to whatever the initial data-value of "rootnode" is
  4.        
  5.         while (data < 100){ //will loop until the data in the latest node is 99 (or < 100)
  6.             Node mostRecent = new Node(data, null);//makes new nodes and puts data in them.
  7.             last.setnext(mostRecent); //makes the node "last" point to the mostRecent we just created... "before the dot" points to "in the parentheses"
  8.             last = mostRecent; //sets last node reference to the new "last node"
  9.             data++;//want to make this increase the data by 1
  10.         }
  11.         return last;
  12.     }
  13.     public static void problem1(Node rootNode){ //method for "problem1" featuring the argument "rootnode"
  14.     //he wants me to take problem0 and insert stuff into it
  15.         double data = rootNode.getdata();
  16.         Node integers = problem0(rootNode);
  17.         Node mostRecent = rootNode;
  18.         while (integers.getdata()<100){//will this let me run through the whole integers(problem0) method?
  19.             //if not, i'm not sure how to make that run...
  20.             /// Try having your terminating condition be if there is a next node. Intuitively, this should
  21.             ///make sense - keep stepping through the list until there isn't a node to step to. You might
  22.             ///need a "break;" command to accomplish this, so if you get stuck, consider it.
  23.  
  24.             //also not sure if i was supposed to set the "return" of problem 0 to last... or something else?
  25.             //as the program is... it prints 99 an only 99... which is the last... but if i have it return "rootnode"
  26.             //it prints 2 and only 2... how do i get it to return the whole list?
  27.  
  28.             /// problem0 should return rootNode. I didn't catch that looking through the first time.
  29.             ///My mistake - as is, you're returning the 99th node, and nodes 1-98 cannot be accessed.
  30.             ///I don't know why, when you return rootNode, it prints 2 and only 2 - could you copy over
  31.             ///the main method?
  32.  
  33.             if (data == 5){
  34.                 for (double minidata = 5.01; minidata <= 6.00; minidata+=0.01){//I know this loop does what i want
  35.                     Node miniNode = new Node(minidata, null);
  36.                     mostRecent.setnext(miniNode);
  37.                     mostRecent = miniNode;
  38.                 }
  39.             }
  40.             if (data == 6){//but i don't know if i even need this part... will it revert to "integers" by itself?
  41.             /// I don't understand your question, but i don't think you need this if. what are you
  42.             ///trying to account for here?
  43.                 integers.getnext();
  44.             }
  45.         data++;
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement