Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Does this code do everything the question asks ? JAVA public int value(Node node

ID: 3806456 • Letter: D

Question

Does this code do everything the question asks ? JAVA

public int value(Node node)

{
int value=node.data; //Saves data in node of node, passed in the function
int diffNode=0; //to count no. of data different from the value
int linkscount=0; //to count total number of links
while(node!=null)
{
if(node.data!=value) //There would be a minor change here. SInce this function doesn't have "target" node, and hence, "target.data" will give error.
//So, we replace it with "value=node.data". When node changes after every loop, the data in "value" is same, used to compare data of every node.
{
diffNode++;
}
linkscount++; //THis increment operation would be outside the "if" condition
node=node.prev; // going back to previous node
}
return diffNode+linkscount; //returning the sum of diffNode and linkscount

}

b. A value method value PLUS the number Node letters different number of and returns the of (node) takes a links back to start

Explanation / Answer

Yes the code looks fine,working, try running it on your compiler first, and let me know if any issues.

public int value(Node node)

{
int value=node.data; //Saves data in node of node, passed in the function
int diffNode=0; //to count no. of data different from the value
int linkscount=0; //to count total number of links
while(node!=null)
{
if(node.data!=value) //There would be a minor change here. SInce this function doesn't have "target" node, and hence, "target.data" will give error.
//So, we replace it with "value=node.data". When node changes after every loop, the data in "value" is same, used to compare data of every node.
{
diffNode++;
}
linkscount++; //THis increment operation would be outside the "if" condition
node=node.prev; // going back to previous node
}
return diffNode+linkscount; //returning the sum of diffNode and linkscount

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote