Question: Please fix the following JAVA code so that it compiles: //////////////////////////////////////////////////////////////////// Exception in thread main java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: CircularList.newlink at

Please fix the following JAVA code so that it compiles:

////////////////////////////////////////////////////////////////////

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: CircularList.newlink

at CircularList.insert(Lab5.java:26)

at Lab5.main(Lab5.java:150)

///////////////////////////////////////////////////////////////////

class CircularList {

private Link current;

private Link prev;

public CircularList() {

current = null;

prev = null;

// implement: set both current and prev to null }

public boolean isEmpty() {

return (current == null);

// implement }

public void insert(int id) {

Link newlink = newlink(id);

if (current == null) {

current = prev = newLink;

} else {

current.previous = newlink; } prev = newLink; newLink.next = current // implement: insert the new node behind the current node

}

public Link delete() {

Link temp = current;

if (current.next == null) {

current = null;

return;

} else {

current.id = current.next.id;

temp = current.next;

temp = null;

current.next = current.next.next;

// implement: delete the node referred by current }

public Link delete(int id) {

if (current.id == id) {

current.previous = current;

current.previous.previous = prev;

} else {

while (current.id != id) {

current = current.previous;

if (current == null) { return null; // not found } }

if (current == prev) {

current = prev.next;

prev = prev.previous;

}

// implement: delete the node with value id // if no node with the id exists, return null return null;

}

public void displayList() {

System.out.println("Values in the list are") '

while (prev != null) {

System.out.println(current.id + " , ");

current = current.previous;

prev = prev.previous;

}

// implement: print all the list element values once, each value seperated by comma

}

class Link {

private int id;

private Link next;

public Link(int id1) {

id1 = id

}

// implement }

public String toString() {

return String.valueOf(id);

}

}

public class Lab5 {

public static void main(String[] args) {

CircularList theList = new CircularList();

theList.insert(10);

theList.insert(20);

theList.insert(15);

theList.insert(5);

theList.insert(30);

theList.displayList();

System.out.println(theList.delete());

theList.delete(15);

theList.displayList();

while (!theList.isEmpty()) {

Link aLink = theList.delete();

System.out.println("Deleted: " + aLink);

}

if (!theList.isEmpty()) { System.out.println("Program error"); } else { System.out.println("Program success"); }

}

}

//////////////////////////////////////////////////////

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!