
Given the IntNode class, define the getCount() method in the CustomLinkedList class that returns the number of items in the list not including the head node.
Ex: If the list contains:
head -> 14 -> 19 -> 4
getCount(headObj) returns 3.
Ex: If the list contains:
head ->
getCount(headObj) returns 0.
public class IntNode {
private int dataVal; // Node data
private IntNode nextNodePtr; // Reference to the next node
// Default constructor
public IntNode() {
dataVal = 0;
nextNodePtr = null;
}
// Constructor
public IntNode(int dataInit) {
this.dataVal = dataInit;
this.nextNodePtr = null;
}
// Constructor
public IntNode(int dataInit, IntNode nextLoc) {
this.dataVal = dataInit;
this.nextNodePtr = nextLoc;
}
/* Insert node after this node.
Before: this -- next
After: this -- node -- next
*/
public void insertAfter(IntNode nodeLoc) {
IntNode tmpNext;
tmpNext = this.nextNodePtr;
this.nextNodePtr = nodeLoc;
nodeLoc.nextNodePtr = tmpNext;
}
// Get location pointed by nextNodePtr
public IntNode getNext() {
return this.nextNodePtr;
}
// Get node value
public int getNodeData() {
return this.dataVal;
}
// Print node value
public void printNodeData() {
System.out.println(this.dataVal);
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------------
public class CustomLinkedList {
// TODO: Return number of nodes in list
public static int getCount(IntNode headObj) {
/* insert your code here */
return
}
public static void main(String[] args) {
IntNode headObj;
IntNode currObj;
IntNode lastObj;
int i;
int count;
// Create head node
headObj = new IntNode(-1);
lastObj = headObj;
// Add nodes to the list
for (i = 0; i < 20; ++i) {
currObj = new IntNode(i);
lastObj.insertAfter(currObj);
lastObj = currObj;
}
count = getCount(headObj);
System.out.println(count);
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 5 images

- In Java please help with the following: Sees whether this list is empty.@return True if the list is empty, or false if not. */ public boolean isEmpty(); } // end ListInterface Hint:Node class definition should look something like: public class Node<T> { T element; Node next; Node prev; public Node(T element, Node next, Node prev) { this.element = element;this.next = next;this.prev = prev; } }arrow_forwardRedesign LaptopList class from previous project public class LaptopList { private class LaptopNode //inner class { public String brand; public double price; public LaptopNode next; public LaptopNode(String brand, double price) { // add your code } public String toString() { // add your code } } private LaptopNode head; // head of the linked list public LaptopList(String fname) throws IOException { File file = new File(fname); Scanner scan = new Scanner(file); head = null; while(scan.hasNextLine()) { // scan data // create LaptopNode // call addToHead and addToTail alternatively } } private void addToHead(LaptopNode node) { // add your code } private void addToTail(LaptopNode node) { // add your code } private…arrow_forwardJava programming language I have to create a remove method that removes the element at an index (ind) or space in an array and returns it. Thanks! I have to write the remove method in the code below. i attached the part where i need to write it. public class ourArrayList<T>{ private Node<T> Head = null; private Node<T> Tail = null; private int size = 0; //default constructor public ourArrayList() { Head = Tail = null; size = 0; } public int size() { return size; } public boolean isEmpty() { return (size == 0); } //implement the method add, that adds to the back of the list public void add(T e) { //HW TODO and TEST //create a node and assign e to the data of that node. Node<T> N = new Node<T>();//N.mData is null and N.next is null as well N.setsData(e); //chain the new node to the list //check if the list is empty, then deal with the special case if(this.isEmpty()) { //head and tail refer to N this.Head = this.Tail = N; size++; //return we are done.…arrow_forward
- Can you please answer this fast and with correct answer. Thankyouarrow_forwardGiven the following definition for a LinkedList: // LinkedList.h class LinkedList { public: LinkedList(); // TODO: Implement me void printEveryOther() const; private: struct Node { int data; Node* next; }; Node * head; }; // LinkedList.cpp #include "LinkedList.h" LinkedList::LinkedList() { head = nullptr; } Implement the function printEveryOther, which prints every other data value (i.e. those at the odd indices assuming 0-based indexing).arrow_forwardPlease fill in all the code gaps if possible: (java) public class LinkedList { privateLinkedListNode head; **Creates a new instance of LinkedList** public LinkedList () { } public LinkedListNode getHead() public void setHead (LinkedListNode head) **Add item at the front of the linked list** public void insertFront (Object item) **Remove item at the front of linked list and return the object variable** public Object removeFront() }arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





