diff --git a/work/Test01/LinkedList.class b/work/Test01/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..3f2ccb48da8e7bb88cfab8e5821d9c060ba468bf Binary files /dev/null and b/work/Test01/LinkedList.class differ diff --git a/work/Test01/LinkedList.java b/work/Test01/LinkedList.java new file mode 100644 index 0000000000000000000000000000000000000000..a34231f994a1dbfcf6619694df1aa3127baa6762 --- /dev/null +++ b/work/Test01/LinkedList.java @@ -0,0 +1,55 @@ +public class LinkedList { + private Node head; + private Node tail; + + public LinkedList() { + head = null; + tail = null; + } + + public void addToFront(E item) { + Node node = new Node(item); + + if (this.head == null) { + this.head = node; + this.tail = this.head; + } else{ + Node temp = head; + this.head = node; + this.head.next = temp; + } + } + + + public void addToRear(E item) { + Node newNode = new Node(item); + if (this.head == null) { + this.head = newNode; + this.tail = this.head; + } else { + + Node temp = this.tail; + tail = newNode; + temp.next = tail; + /* + Node temp = this.head; + while(temp.next != null){ + temp = temp.next; + } + temp.next = newNode; + tail = temp.next; + */ + + } + } + + public void print() { + Node temp = this.head; + while(temp.next != null){ + System.out.print(temp.item + " -> "); + temp = temp.next; + } + System.out.println(temp.item); + } +} + diff --git a/work/Test01/Main.class b/work/Test01/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..acd5ba79cd19013b43688c117c0f04ebc61dbca7 Binary files /dev/null and b/work/Test01/Main.class differ diff --git a/work/Test01/Main.java b/work/Test01/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..221188321937460926e3b7b499ef77b0ca60a9c4 --- /dev/null +++ b/work/Test01/Main.java @@ -0,0 +1,15 @@ +class Main { + public static void main(String[] args) { + LinkedList ll = new LinkedList(); + ll.addToFront(1); + ll.addToFront(2); + ll.addToFront(5); + ll.addToFront(6); + ll.addToFront(7); + ll.addToRear(3); + ll.addToRear(8); + ll.addToRear(9); + ll.addToRear(10); + ll.print(); + } +} \ No newline at end of file diff --git a/work/Test01/Node.class b/work/Test01/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..a383363383e004072772b0293411ecf05b408603 Binary files /dev/null and b/work/Test01/Node.class differ diff --git a/work/Test01/Node.java b/work/Test01/Node.java new file mode 100644 index 0000000000000000000000000000000000000000..5f1555858f49dd1b3d668202d01aaf8b55124a9a --- /dev/null +++ b/work/Test01/Node.java @@ -0,0 +1,7 @@ +public class Node { + E item; + Node next = null; + Node(E item) { + this.item = item; + } +} \ No newline at end of file diff --git a/work/Test02/LinkedList.class b/work/Test02/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..202467e741c2844d4a03aa3bbf3435e2a306ed93 Binary files /dev/null and b/work/Test02/LinkedList.class differ diff --git a/work/Test02/LinkedList.java b/work/Test02/LinkedList.java new file mode 100644 index 0000000000000000000000000000000000000000..fcf4b2107e7a6f8b7e7137a476a69fb544fa771c --- /dev/null +++ b/work/Test02/LinkedList.java @@ -0,0 +1,48 @@ +public class LinkedList { + private Node head; + private Node tail; + + public LinkedList() { + head = null; + tail = null; + } + + public void addToFront(E item) { + Node node = new Node(item); + + if (this.head == null) { + this.head = node; + this.tail = this.head; + } else{ + Node temp = head; + this.head = node; + this.head.next = temp; + temp.pre = this.head; + //temp = null; + } + } + + public void addToRear(E item) { + Node newNode = new Node(item); + if (this.head == null) { + this.head = newNode; + this.tail = this.head; + } else { + + Node temp = this.tail; + tail = newNode; + tail.pre = temp; + temp.next = tail; + } + } + + public void print() { + Node temp = this.head; + while(temp.next != null){ + System.out.print(temp.item + " -> "); + temp = temp.next; + } + System.out.println(temp.item); + } +} + diff --git a/work/Test02/Main.class b/work/Test02/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..acd5ba79cd19013b43688c117c0f04ebc61dbca7 Binary files /dev/null and b/work/Test02/Main.class differ diff --git a/work/Test02/Main.java b/work/Test02/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..221188321937460926e3b7b499ef77b0ca60a9c4 --- /dev/null +++ b/work/Test02/Main.java @@ -0,0 +1,15 @@ +class Main { + public static void main(String[] args) { + LinkedList ll = new LinkedList(); + ll.addToFront(1); + ll.addToFront(2); + ll.addToFront(5); + ll.addToFront(6); + ll.addToFront(7); + ll.addToRear(3); + ll.addToRear(8); + ll.addToRear(9); + ll.addToRear(10); + ll.print(); + } +} \ No newline at end of file diff --git a/work/Test02/Node.class b/work/Test02/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..d5d0e569664ec23fdd06c248a33be2f4e3f1a48a Binary files /dev/null and b/work/Test02/Node.class differ diff --git a/work/Test02/Node.java b/work/Test02/Node.java new file mode 100644 index 0000000000000000000000000000000000000000..ef186f85aaa659cb3dacbb507aec4ceaaf55e633 --- /dev/null +++ b/work/Test02/Node.java @@ -0,0 +1,8 @@ +public class Node { + E item; + Node next = null; + Node pre = null; + Node(E item) { + this.item = item; + } +} \ No newline at end of file