Question: Linked List Remove Using this code: public class IntNode { private int dataVal; // Node data private IntNode nextNodePtr; // Reference to the next node

Linked List Remove

Using this code:

public class IntNode { private int dataVal; // Node data private IntNode nextNodePtr; // Reference to the next node 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; } public void printNodeData() { System.out.println(this.dataVal); } }

Write a main program which generates a list containing 10 integers asks the user to input an integer finds and removes the node containing this integer prints out Integer removed, or Not found if integer is not in list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!