From 8e1bd3b05dc96617833bb3a91f0a674cf15a5183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=92=A7=E5=9E=AB=E6=AA=BD=E9=90=9E=E7=A0=95?= <407837686@qq.com> Date: Tue, 3 Nov 2020 23:07:34 +0800 Subject: [PATCH] AutoPush --- ...6\347\275\256\350\264\246\345\217\267.bat" | 2 + ...7\346\215\242\345\210\206\346\224\257.bat" | 2 + .../LinkList.java" | 59 +++++ .../Node.java" | 38 ++++ .../TryToRun.java" | 12 + ...347\220\263 \351\223\276\350\241\250.java" | 215 ++++++++++++++++++ ...2\345\212\250\346\217\220\344\272\244.bat" | 3 + LinkList.java | 59 +++++ TryToRun.java | 12 + 9 files changed, 402 insertions(+) create mode 100644 "1,\350\256\276\347\275\256\350\264\246\345\217\267.bat" create mode 100644 "2,\345\210\207\346\215\242\345\210\206\346\224\257.bat" create mode 100644 "20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/LinkList.java" create mode 100644 "20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/Node.java" create mode 100644 "20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/TryToRun.java" create mode 100644 "20200340948\350\265\265\346\231\223\347\220\263 \351\223\276\350\241\250.java" create mode 100644 "3,\350\207\252\345\212\250\346\217\220\344\272\244.bat" create mode 100644 LinkList.java create mode 100644 TryToRun.java diff --git "a/1,\350\256\276\347\275\256\350\264\246\345\217\267.bat" "b/1,\350\256\276\347\275\256\350\264\246\345\217\267.bat" new file mode 100644 index 0000000..ff2c8e4 --- /dev/null +++ "b/1,\350\256\276\347\275\256\350\264\246\345\217\267.bat" @@ -0,0 +1,2 @@ +git config --global user.name "赵晓琳Z" +git config --global user.email "407837686@qq.com" \ No newline at end of file diff --git "a/2,\345\210\207\346\215\242\345\210\206\346\224\257.bat" "b/2,\345\210\207\346\215\242\345\210\206\346\224\257.bat" new file mode 100644 index 0000000..416695a --- /dev/null +++ "b/2,\345\210\207\346\215\242\345\210\206\346\224\257.bat" @@ -0,0 +1,2 @@ +git branck 48 +git checkout 48 \ No newline at end of file diff --git "a/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/LinkList.java" "b/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/LinkList.java" new file mode 100644 index 0000000..07d72b3 --- /dev/null +++ "b/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/LinkList.java" @@ -0,0 +1,59 @@ +package datastruct.linklist; + +public class LinkList { + + private Node head; + + public void addToRear(Object data){ + Node node = new Node(data); + Node head = this.head; + while (true){ + if (head.getNext()==null){ + head.setNext(node); + System.out.println("尾部添加:" + head.toString()); + return; + } + } + } + + public void addToFront(Object data){ + Node node = new Node(data); + node.setNext(this.head); + this.head = node; + System.out.println("头部添加:" + head.toString()); + return; + } + + public void removeItem(Object object){ + Node head = this.head; + if (head.getData().equals(object)){ + this.head = head.getNext(); + System.out.println("已删除:" + head.toString()); + return; + } + while (true){ + if (head.getNext().getData().equals(object)){ + System.out.println("已删除:" + head.getNext()); + head.setNext(head.getNext().getNext()); + return; + } + head = head.getNext(); + } + } + + public LinkList(Object data) { + this.head = new Node(data); + } + + @Override + public String toString(){ + Node head = this.head; + StringBuilder printStr = new StringBuilder("链表:"); + while (head!=null){ + printStr.append(head.getData().toString()); + printStr.append(" --> "); + head = head.getNext(); + } + return printStr.toString(); + } +} diff --git "a/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/Node.java" "b/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/Node.java" new file mode 100644 index 0000000..2b0e955 --- /dev/null +++ "b/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/Node.java" @@ -0,0 +1,38 @@ +package datastruct.linklist; + +public class Node { + private Object data; + private Node next; + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public Node getNext() { + return next; + } + + public void setNext(Node next) { + this.next = next; + } + + public Node(Object data) { + this.data = data; + } + + public Node(Object data, Node next) { + this.data = data; + this.next = next; + } + + @Override + public String toString() { + return "Node{" + + "data=" + data + + '}'; + } +} diff --git "a/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/TryToRun.java" "b/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/TryToRun.java" new file mode 100644 index 0000000..67d4d46 --- /dev/null +++ "b/20200340921\350\265\265\346\231\223\347\220\263\344\275\234\344\270\232/TryToRun.java" @@ -0,0 +1,12 @@ +package datastruct.linklist; + +public class TryToRun { + public static void main(String[] args) { + //没有多次测试,若有问题及时反馈 + LinkList linkList = new LinkList("a"); + linkList.addToRear("b"); + linkList.addToFront("c"); + linkList.removeItem("a"); + System.out.println(linkList.toString()); + } +} diff --git "a/20200340948\350\265\265\346\231\223\347\220\263 \351\223\276\350\241\250.java" "b/20200340948\350\265\265\346\231\223\347\220\263 \351\223\276\350\241\250.java" new file mode 100644 index 0000000..3779cc8 --- /dev/null +++ "b/20200340948\350\265\265\346\231\223\347\220\263 \351\223\276\350\241\250.java" @@ -0,0 +1,215 @@ + +public class LinkListimplements Iterable{ + private Node head; + private int N; + private class Node{ + T item; + Node next; + public Node(T item,Node next){ + this.item=item; + this.next=next; + } + } + +public LinkList(){ + this.head=new Node(item:null,next:null); + this .N=0; +} +public void clear(){ + head.next=null; + this.N=0; +} +public int length(){ + return N; +} +public boolean isEmpty(){ + return N==0; +} +public T get(int i){ + Node n=head.next; + for(int index=0;index Iterator(){ + return new LIterator; +} +private class LIterator implements Iterator{ + private Node n; + public Lterator(){ + this.n=head; + } + public boolean hasNext(){ + return n.next=null; + } + public object next(){ + n=n.next; + return n.item; + } +} +} + + + +˫ + +public class TowWayLinkListimplements Iterable{ + +} + + +private class Node{ + public Node(T item,Node pre,Node next){ + this.item=item; + this.pre=pre; + this.next=next; + } + public T item; + public Node pre; + public Node next; +} +public TowWayLinkList(){ + this.head=new Node(item:null,pre:null,next:null); + this.last=null; + this.N=0; +} +public void clear(){ + this.head.next=null; + this.head.pre=null; + this.head.item=null; + this.last=null; + this.N=0; +} +public int length(){ + return N; +} +public boolean isEmpty(){ + return N==0; +} +public T getFirst(){ + if(isEmpty()){ + return null; + } + return head.next.item; +} +public T getLast(){ + if(isEmpty()){ + return null; + } + return last.item; +} +public void insert(T t){ + if(isEmpty()){ + Node newNode=new Node(t,head,next:null); + last=newNode; + head.next=last; + }else{ + Node oldLast=last; + Node newNode=new Node(t,oldLast,next:null); + oldLast.next=newNode; + last=newNode; + } + N++; +} + +public void insert(int i,T t){ + Node pre=head; + for(int index=0;index iterator(){ + return new TIterator; +} +private class TIterator implements Iterator{ + private Node n; + public TIterator(){ + this.n=head; + } + public boolean hasNext(){ + return n.next!=null; + } + public Object next(){ + n=n.next; + return n.item; + } +} +} \ No newline at end of file diff --git "a/3,\350\207\252\345\212\250\346\217\220\344\272\244.bat" "b/3,\350\207\252\345\212\250\346\217\220\344\272\244.bat" new file mode 100644 index 0000000..0fbd52f --- /dev/null +++ "b/3,\350\207\252\345\212\250\346\217\220\344\272\244.bat" @@ -0,0 +1,3 @@ +git add . +git commit -m "AutoPush" +git push \ No newline at end of file diff --git a/LinkList.java b/LinkList.java new file mode 100644 index 0000000..07d72b3 --- /dev/null +++ b/LinkList.java @@ -0,0 +1,59 @@ +package datastruct.linklist; + +public class LinkList { + + private Node head; + + public void addToRear(Object data){ + Node node = new Node(data); + Node head = this.head; + while (true){ + if (head.getNext()==null){ + head.setNext(node); + System.out.println("尾部添加:" + head.toString()); + return; + } + } + } + + public void addToFront(Object data){ + Node node = new Node(data); + node.setNext(this.head); + this.head = node; + System.out.println("头部添加:" + head.toString()); + return; + } + + public void removeItem(Object object){ + Node head = this.head; + if (head.getData().equals(object)){ + this.head = head.getNext(); + System.out.println("已删除:" + head.toString()); + return; + } + while (true){ + if (head.getNext().getData().equals(object)){ + System.out.println("已删除:" + head.getNext()); + head.setNext(head.getNext().getNext()); + return; + } + head = head.getNext(); + } + } + + public LinkList(Object data) { + this.head = new Node(data); + } + + @Override + public String toString(){ + Node head = this.head; + StringBuilder printStr = new StringBuilder("链表:"); + while (head!=null){ + printStr.append(head.getData().toString()); + printStr.append(" --> "); + head = head.getNext(); + } + return printStr.toString(); + } +} diff --git a/TryToRun.java b/TryToRun.java new file mode 100644 index 0000000..67d4d46 --- /dev/null +++ b/TryToRun.java @@ -0,0 +1,12 @@ +package datastruct.linklist; + +public class TryToRun { + public static void main(String[] args) { + //没有多次测试,若有问题及时反馈 + LinkList linkList = new LinkList("a"); + linkList.addToRear("b"); + linkList.addToFront("c"); + linkList.removeItem("a"); + System.out.println(linkList.toString()); + } +} -- Gitee