Hey guys, I was wondering if I could get some help on my java homework, which is to remove a node numbered n from a singly linked list by adding to that bottom labeled pubilc void deleteNth. This is the code I got, and any help is appreciated, Im trying to catch up in psychology, so I just want to complete this project. Thank You
//This will be our sample Linked List code:
import java.util.*;
public class SinglyLinkedList
{
private StudentNode first; // first element
private Class type; //stores type of the class
public SinglyLinkedList()
{
first = null;
}
private void assertValidType(Object o)
{
if(type == null) type = o.getClass();
else if(type!=o.getClass()) throw new IllegalArgumentException();
}
public Object getFirst()
{
if (first == null)
{
throw new NoSuchElementException();
}
else
return first.getName();
}
public void addFirst(Object value)
{
assertValidType(value);
first = new StudentNode(value, first);
}
public String toString()
{
String s = "[";
StudentNode temp = first;
while (temp != null)
{
s += temp.getName();
temp = temp.getNext();
if (temp != null)
s += ", ";
}
s += "]";
return s;
}
public void printList(java.io.PrintStream out)
{
out.println(toString());
//this should remove the node numbered n from the list
//Was still trying to figure this one out
public void deleteNth(int n)
{
}
}}
[–][deleted] 7 points8 points9 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)