diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 4be381c..a07d5fa 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -6,11 +6,13 @@
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..712ab9d
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml
new file mode 100644
index 0000000..d411041
--- /dev/null
+++ b/.idea/libraries/Maven__junit_junit_4_12.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
new file mode 100644
index 0000000..f58bbc1
--- /dev/null
+++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index ad4fefc..8b9083f 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -3,6 +3,7 @@
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b6d36bd..623ab77 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,86 +1,37 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index ffa3f40..6bbb3a4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,6 +7,14 @@
com.zipcodewilmington
singlylinkedlist
1.0-SNAPSHOT
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
\ No newline at end of file
diff --git a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java
index 2fb3165..954664b 100644
--- a/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java
+++ b/src/main/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedList.java
@@ -1,7 +1,147 @@
package com.zipcodewilmington.singlylinkedlist;
+import javax.xml.soap.Node;
+import java.util.Iterator;
+import java.util.List;
+
/**
* Created by leon on 1/10/18.
*/
-public class SinglyLinkedList {
+public class SinglyLinkedList implements Iterable {
+
+
+ public Iterator iterator() {
+ return null;
+ }
+
+
+
+ class Node {
+ Object data;
+ Node next;
+
+ public Node(Object data) {
+ this.data = data;
+ next = null;
+ }
+
+ }
+
+ public Node head;
+ public Node tail;
+
+ public void add(Object data) {
+ Node newNode = new Node(data);
+ if (this.head == null) {
+ this.head = newNode;
+ } else {
+ tail.next = newNode;
+ }
+ tail = newNode;
+
+ }
+
+ public void remove(int index) {
+ Node current = this.head;
+ Node previous = null;
+
+ if (index == 0 && current != null) { //this removes the head value
+ this.head = current.next;
+ }
+
+ int counter = 0;
+ while (current != null) {
+ if (counter == index) {
+ previous.next = current.next;
+
+ break;
+ } else {
+ previous = current; //[head] -> [current] -> [current.next] -> []
+ current = current.next;
+ counter++;
+ }
+ }
+ if (current == null) {
+ System.out.println("not found");
+ }
+ }
+
+ public Boolean contains(Object key) {
+ Node current = this.head;
+ while (current != null) {
+ if (current.data == key) {
+ return true;
+ }
+ current = current.next;
+
+ }
+ return false;
+ }
+
+ public int size() {
+ int counter = 0;
+ Node current = head;
+ while (current != null) {
+ counter++;
+ current = current.next;
+ }
+ return counter;
+
+ }
+
+ public Integer find(int data) { // [head] -> [current] -> [current.next] -> []
+ Node current = this.head;
+ int index = 0;
+ while (current != null) {
+ if (current.data.equals(data)) {
+ return index;
+
+ }
+ index++;
+ current = current.next;
+ }
+
+
+ return -1;
+ }
+
+ public Object get(int index) {
+ Node current = this.head;
+ int seek = 0;
+ while (current != null) {
+ if (seek == index) {
+ return current.data;
+ }
+ seek++;
+ current = current.next;
+ }
+
+ return -1;
+ }
+
+ public SinglyLinkedList copy() {
+ SinglyLinkedList copiedList = new SinglyLinkedList();
+ Node current = this.head;
+ while(current != null){
+ copiedList.add(current.data);
+ current = current.next;
+ }
+
+ return copiedList;
+ }
+ public void sort() {
+ Node current = this.head;
+ for(int i = 0; i < size(); i++){
+ while(current.next != null){
+ Node next = current.next;
+ if((Integer)current.data > (Integer) next.data){
+ Object temp = current.data;
+ current.data = next.data;
+ next.data = temp;
+ }
+ current = current.next;
+ }
+ }
+ }
+
}
diff --git a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java
index 5cc057e..589a69b 100644
--- a/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java
+++ b/src/test/java/com/zipcodewilmington/singlylinkedlist/SinglyLinkedListTest.java
@@ -1,7 +1,196 @@
package com.zipcodewilmington.singlylinkedlist;
+import org.junit.Assert;
+import org.junit.Test;
+
/**
* Created by leon on 1/10/18.
*/
public class SinglyLinkedListTest {
+ @Test
+ public void addTest() {
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+
+ //when
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ int actual = list.size();
+ int expected = 5;
+
+ //then
+ Assert.assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void containsTest1() {
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ //when
+ Boolean expected = true;
+ Boolean actual = list.contains(2);
+
+ //then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void containsTest2() {
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ //when
+ Boolean check = list.contains(6);
+
+ //then
+ Assert.assertFalse(check);
+ }
+
+ @Test
+ public void remove1() {
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ //when
+ list.remove(2);
+ int expected = list.size();
+ int actual = 4;
+
+ //then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void remove2() {
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ //when
+ list.remove(1);
+ list.remove(2);
+
+ int expected = list.size();
+ int actual = 3;
+
+ //then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void findTest1() {
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ //when
+ int expected = list.find(2);
+ int actual = 1;
+
+ //then
+ Assert.assertEquals(expected, actual);
+ }
+
+ @Test
+ public void findTest2() {
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ //when
+ int expected = list.find(6);
+ int actual = -1;
+
+ //then
+ Assert.assertEquals(expected, actual);
+ }
+ @Test
+ public void getTest1(){
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(8);
+ list.add(4);
+ list.add(5);
+
+ //when
+ Object expected = list.get(2);
+ Object actual = 8;
+
+ //then
+ Assert.assertEquals(expected,actual);
+ }
+ @Test
+ public void copyTest(){
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(1);
+ list.add(2);
+ list.add(3);
+ list.add(4);
+ list.add(5);
+
+ //when
+ SinglyLinkedList newList = list.copy();
+ Integer expected = list.size();
+ Integer actual = newList.size();
+
+
+ //then
+ Assert.assertEquals(expected,actual);
+ }
+ @Test
+ public void sort(){
+ //given
+ SinglyLinkedList list = new SinglyLinkedList();
+ list.add(3);
+ list.add(1);
+ list.add(2);
+ list.add(5);
+ list.add(4);
+
+ //when
+ list.sort();
+
+ //then
+ Assert.assertTrue(list.find(1) == 0);
+ Assert.assertTrue(list.find(2) == 1);
+ Assert.assertTrue(list.find(3) == 2);
+ Assert.assertTrue(list.find(4) == 3);
+ Assert.assertTrue(list.find(5) == 4);
+ }
}