diff --git "a/23\346\235\216\351\224\256\344\275\234\344\270\232/src/LinkedList.java" "b/23\346\235\216\351\224\256\344\275\234\344\270\232/src/LinkedList.java" new file mode 100644 index 0000000000000000000000000000000000000000..bf7478233274bbe7001e251d09af9ae0404835f5 --- /dev/null +++ "b/23\346\235\216\351\224\256\344\275\234\344\270\232/src/LinkedList.java" @@ -0,0 +1,101 @@ +public class LinkedList { + private NodeList head; + private NodeList tail; //尾指针用来标记最后一个结点的位置 + private int size;//长度用来标记长度 + public LinkedList() { + head = null; + } + + public void addToFront(T item) { + NodeList node = new NodeList(item); + + if (this.head == null) { + this.head = node; + } else{ + NodeList temp = head; + node.next=temp; + head = node; + } + this.size++; + } + + public int size(){ + return this.size; + } + + public void addToRear(T item) { + NodeList newNode = new NodeList(item); + if (this.head == null) { + this.head = newNode; + } + this.tail = newNode; + this.size++; + } + + public void deleteItems(T item){ + NodeList temp=this.head; + NodeList pretemp=new NodeList(item); + pretemp=temp; + if(temp==null){ + System.out.println("empty"); + return; + } + while(temp.next!=null){ + // System.out.println("temp"+temp.item); + // System.out.println("ll"+this.head.item); + if(temp.item.equals(item)){ + if(this.head.item.equals(item)){ + pretemp=this.head.next; + this.head.next=pretemp.next; + this.head=pretemp; + + // System.out.println("testss"+this.head.item); + break; + } + System.out.println("delete"); + pretemp.next=temp.next; + break; + }else + { + System.out.println("no delete"); + pretemp=temp; + temp=temp.next; + + } + + } + if(temp.next==null){ + temp.item=null; + temp.next=null; + } + this.tail=temp; + // System.out.println(tail.item); + this.size--; + } + + public boolean findItems(T item){ + NodeList temp=this.head; + if(temp==null){ + System.out.println("empty"); + return false; + } + while(temp.next!=null){ + if(temp.item.equals(item)) + { + return true; + } + temp=temp.next; + } + return false; + } + + public void printItems() { + NodeList temp = this.head; + // System.out.println("testss"+temp.item); + while(temp.next != null){ + System.out.print(temp.item + " -> "); + temp = temp.next; + } + System.out.println(temp.item); + } +} diff --git "a/23\346\235\216\351\224\256\344\275\234\344\270\232/src/Main.java" "b/23\346\235\216\351\224\256\344\275\234\344\270\232/src/Main.java" new file mode 100644 index 0000000000000000000000000000000000000000..65496e3fa809525dc6aac9db06039df61d822c4a --- /dev/null +++ "b/23\346\235\216\351\224\256\344\275\234\344\270\232/src/Main.java" @@ -0,0 +1,13 @@ +public class Main { + public static void main(String args[]) { + LinkedList ll = new LinkedList(); + ll.addToFront("1"); + ll.addToFront("2"); + ll.addToRear("3"); + ll.deleteItems("1"); + ll.printItems(); + + System.out.println(ll.size()); + System.out.println(ll.findItems("2")); + } +} diff --git "a/23\346\235\216\351\224\256\344\275\234\344\270\232/src/Node.java" "b/23\346\235\216\351\224\256\344\275\234\344\270\232/src/Node.java" new file mode 100644 index 0000000000000000000000000000000000000000..2e1595f892bc852405c8407d619f7a4c37ef3f37 --- /dev/null +++ "b/23\346\235\216\351\224\256\344\275\234\344\270\232/src/Node.java" @@ -0,0 +1,9 @@ + + class NodeList { + T item; + NodeList next = null; + NodeList(T item) { + this.item = item; + } + } + diff --git a/666.txt b/666.txt new file mode 100644 index 0000000000000000000000000000000000000000..d91db81d702c02be1225e20c334c26b1250b30eb --- /dev/null +++ b/666.txt @@ -0,0 +1 @@ +4566 \ No newline at end of file diff --git a/Node.class b/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..f3a6d714a73a506f60c219b2e1abad3f4cd3565d Binary files /dev/null and b/Node.class differ