Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Last active December 12, 2015 19:18
Show Gist options
  • Save AnnaBoro/f0ea32675ec63a3b0979 to your computer and use it in GitHub Desktop.
Save AnnaBoro/f0ea32675ec63a3b0979 to your computer and use it in GitHub Desktop.
MyList4 + addLast()
package lesson7.mylist;
public class SimpleLinkedList {
private Node root;
private int size;
public SimpleLinkedList() {
size = 0;
}
public void addFirst(Object o) {
Node node = new Node();
node.object = o;
if(root != null) {
node.node = root;
}
root = node;
size++;
}
public void addLast(Object o) {
Node nodeNew = new Node();
nodeNew.object = o;
if (root != null) {
Node gapNode = root.node;
Node gap = root.node;
while (gapNode != null) {
gap = gapNode;
gapNode = gapNode.node;
}
gap.node = nodeNew;
size++;
}
else addFirst(o);
}
public void addAfter(Object o, Object n) {
}
public int getSize() {
return size;
}
private class Node {
private Object object;
private Node node;
public Node() {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment