data structures and algorithms in java Question 3. (4 marks) Consider the follow
ID: 3711310 • Letter: D
Question
data structures and algorithms in java
Question 3. (4 marks) Consider the following two classes Node and DoublyLinkedlist: private class Node private int element; private Node prev: private Node next; public Node (int e, Node n, Node p) element - e; next = n; prev - P: { return element;} public int getElement() { return next;} public Node getNext () public void setNext (Node n) { next = n;} { return prev:) public Node getPrev() public void set Prev (Node p) { prev = p;} public class DoublyLinkedlist private Node header; private Node trailer; private int size = 0; Add the method countInt () that returns the number of times a specific integer value is stored in a List of the DoublyLinkedlist class.Explanation / Answer
public int countInt(int num) { Node temp = header; int count = 0; while (temp != null) { if(temp.getElement() == num) { count++; } temp = temp.getNext(); } return count; }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.