Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Node problem0(Node rootNode) {//method for your "problem0" which is going to deal with "rootnode"
- Node last = rootNode; //setting "next" local variable to "rootnode"
- double data = rootNode.getdata(); //setting "data" variable to whatever the initial data-value of "rootnode" is
- while (data < 100){ //will loop until the data in the latest node is 99 (or < 100)
- Node mostRecent = new Node(data, null);//makes new nodes and puts data in them.
- last.setnext(mostRecent); //makes the node "last" point to the mostRecent we just created... "before the dot" points to "in the parentheses"
- last = mostRecent; //sets last node reference to the new "last node"
- data++;//want to make this increase the data by 1
- }
- return last;
- }
- public static void problem1(Node rootNode){ //method for "problem1" featuring the argument "rootnode"
- //he wants me to take problem0 and insert stuff into it
- double data = rootNode.getdata();
- Node integers = problem0(rootNode);
- Node mostRecent = rootNode;
- while (integers.getdata()<100){//will this let me run through the whole integers(problem0) method?
- //if not, i'm not sure how to make that run...
- /// Try having your terminating condition be if there is a next node. Intuitively, this should
- ///make sense - keep stepping through the list until there isn't a node to step to. You might
- ///need a "break;" command to accomplish this, so if you get stuck, consider it.
- //also not sure if i was supposed to set the "return" of problem 0 to last... or something else?
- //as the program is... it prints 99 an only 99... which is the last... but if i have it return "rootnode"
- //it prints 2 and only 2... how do i get it to return the whole list?
- /// problem0 should return rootNode. I didn't catch that looking through the first time.
- ///My mistake - as is, you're returning the 99th node, and nodes 1-98 cannot be accessed.
- ///I don't know why, when you return rootNode, it prints 2 and only 2 - could you copy over
- ///the main method?
- if (data == 5){
- for (double minidata = 5.01; minidata <= 6.00; minidata+=0.01){//I know this loop does what i want
- Node miniNode = new Node(minidata, null);
- mostRecent.setnext(miniNode);
- mostRecent = miniNode;
- }
- }
- if (data == 6){//but i don't know if i even need this part... will it revert to "integers" by itself?
- /// I don't understand your question, but i don't think you need this if. what are you
- ///trying to account for here?
- integers.getnext();
- }
- data++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement