Hey everyone,
I am working on an assignment that concerns itself with linked lists. Below is the code for two user-defined classes. The class Node contains the instance variables, constructors, accessors, mutators and print method. The class LinkedList is where I need to write methods for starting the list, inserting a new node, deleting a node, and searching the nodes. Each node contains professor information(which is why I have left the arguments as empty strings when creating them (prof1 and prof2))).
So far I have created the three empty nodes head, last, and temp,which serve only as pointers. I am trying to create the list and have created the node prof1. My question is how do I redirect head to point to prof1 instead of null?. If I write head = prof1 I get the error "Syntax error on token";", , expected" which is indicated on the semicolon of Node prof1 = new Node("", "", "", null);
public class Node { //icams //instance variables private String name; private String researchArea; private String email; private Node link; //constructors public Node() {//default constructor name = ""; researchArea = ""; email = ""; link = null; } public Node(String nameIn, String researchIn, String emailIn, Node newLink) {//constructor with parameters. name = nameIn; researchArea = researchIn; email = emailIn; link = newLink; } //accessors public String getName() { return name; } public String getResearchArea() { return researchArea; } public String getEmail() { return email; } public Node getNode() { return link; } //mutators public void setName(String nameIn) { name = nameIn; } public void setResearchArea(String researchIn) { researchArea = researchIn; } public void setEmail(String emailIn) { email = emailIn; } public void setNode(Node linkIn) { link = linkIn; }
public class LinkedList extends Node { Node head = new Node(); Node last = new Node(); Node temp = new Node(); Node prof1 = new Node("", "", "", null); head = prof1; //Node prof2 = new Node("", "", "", null); }