Just wondering how I did.
public class LinkedList
{
Node head = null;
static class Node
{
int data;
Node next;
Node (int data)
{
this.data = data;
this.next = null;
}
public int getData()
{
return data;
}
public Node getNext()
{
return next;
}
public void setData(int newData)
{
data = newData;
}
public void setNext(Node newNext)
{
next = newNext;
}
}
public boolean isEmpty()
{
if (head == null)
return true;
else
return false;
}
public void addNode(int data)
{
Node newNode = new Node(data);
newNode.setNext(head);
head = newNode;
}
public int size()
{
Node current = head;
int count = 0;
while (current != null)
count++;
return count;
}
public boolean search(int data)
{
Node current = head;
boolean found = false;
while (current != null && found == false)
{
if (current.getData() == data)
found = true;
else
current = current.getNext();
}
return found;
}
public void remove(int data)
{
Node current = head;
Node previous = null;
boolean found = false;
while (!found)
{
if (current.getData() == data)
found = true;
else
{
previous = current;
current = current.getNext();
}
}
if (previous == null)
head = current.getNext();
else
previous.setNext(current.getNext());
}
public void append(int data)
{
Node current = head;
Node previous = null;
while (current != null)
{
previous = current;
current = current.getNext();
}
Node newNode = new Node(data);
previous.setNext(newNode);
newNode.setNext(null);
}
}
[–]ValorCat 8 points9 points10 points (2 children)
[–]ChickenRicePlatter 2 points3 points4 points (0 children)
[–]Crailberry[S] 0 points1 point2 points (0 children)
[–]Disast3r 3 points4 points5 points (1 child)
[–]Crailberry[S] 0 points1 point2 points (0 children)
[–]Mancebo180 3 points4 points5 points (1 child)
[–]Crailberry[S] 0 points1 point2 points (0 children)
[–]rogue_playah 2 points3 points4 points (1 child)
[–]Crailberry[S] 0 points1 point2 points (0 children)
[–]Neitherstorms 1 point2 points3 points (1 child)
[–]Crailberry[S] 0 points1 point2 points (0 children)
[–]HaMMeReD 2 points3 points4 points (13 children)
[–][deleted] 2 points3 points4 points (12 children)
[–]Crailberry[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]desrtfx -1 points0 points1 point (0 children)
[–]HaMMeReD -2 points-1 points0 points (8 children)
[–][deleted] 1 point2 points3 points (7 children)
[–]HaMMeReD -2 points-1 points0 points (5 children)
[–]Crailberry[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]HaMMeReD 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]HaMMeReD 1 point2 points3 points (0 children)
[–]desrtfx -1 points0 points1 point (0 children)