I've been having some "fun" with my program Im making for a class im taking. I thought I handled all of the null pointers correctly but I guess not, heres what I currently have.
I have some experience in C++ dealing with pointers, am I coding in C++ with out realizing it?public class LinkedList { private LinkedListNode first; //holds the first/head of the list private LinkedListNode last; //holds the last/tail of the list private LinkedListNode current; //holds the current node you are at //List constructor public LinkedList() { first = null; //creates the list with no head last = null; //creates the list with no tail current = first; //starts you at the head } //Linked list node class public class LinkedListNode { private Object info; //the information in the node private LinkedListNode next; //a node that points to the next in the list public LinkedListNode() { next = null; //always creates the first node pointing to nothing } } public void insertFirst(Object new_info) { LinkedListNode temp = new LinkedListNode(); temp.info = new_info; if(first == null) { temp = first; temp = last; } else { temp.next = first; temp = first; } }
--- Update ---
Wait found part of the problem, found the issue in the insertFirst method... the head and tail werent being set correctly, i was effectively deleting the node i was inserting. I just got the current node to work properly now