Given a problem description based on a populated linked list of int nodes(data i
ID: 3912754 • Letter: G
Question
Given a problem description based on a populated linked list of int nodes(data is int, ink points to int node), write the contents of a method in a javaesque fashion that solves the problem. Then determine the algebraic formula for the number of steps, determine the Big-o0 Example: iii. Given a linked list of n int nodes with pointer to first node called head, calculate the average of the numbers in the linked list, then calculate the number of nodes that are above the average. The UML for IntNode would be provided for the exam partial hint: for (cursor-head; cursor!- null; cursor cursor.getLink)) IV Given a picture of a linked list of StringNode (UML provided for exam) with some pointers pointing to some nodes ( head to first, cursor pointing to a node, previous pointing to the node before cursor), write the line(s) of code to add a new node before cursor. Example: (like Data Structure Lab 03) add newElement before cursor where newElement is "Mango" cursor previous tail head applebananacherywatermelon cherryExplanation / Answer
Question (III) : Answer : ---------->>>>>>>>>
public int nodes_above_avarage(){
node cursor = null;
int tot = 0;
//head is the first node of the linked list
for(cursor = head;cursor != null;cursor = cursor.getLink()){
tot += cursor.getData();
}
int avg = tot/n;//here n is number of nodes
int numNodes = 0;
for(cursor = head;cursor != null;cursor = cursor.getLink()){
if(cursor.getData() > avg){
numNodes++;
}
}
return numNodes;
}
Question (IV) : Answer : -------------->>>>>>>>>>
node newNode = new node();
newNode.setData("Mango");
newNode.setLink(cursor);
previous.setLink(newNode);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.