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 0000000000000000000000000000000000000000..ac7e603f607b06a8dea612634ab3d16bac6cb9d2 --- /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 "苏瑜煌" +git config --global user.email "1394157072@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 0000000000000000000000000000000000000000..1ec69c41c0deeb98cfd6290e04f42c025b86b003 --- /dev/null +++ "b/2,\345\210\207\346\215\242\345\210\206\346\224\257.bat" @@ -0,0 +1,2 @@ +git branck 39 +git checkout 39 \ 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 0000000000000000000000000000000000000000..0fbd52fa8111ae13721da1f2c119822552292813 --- /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/LinkedList.class b/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..6ef66110d88697e6bd9c60ade2a9b27f636862de Binary files /dev/null and b/LinkedList.class differ diff --git a/Main.class b/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..409939c34c612a3841273627b83d7748904a1807 Binary files /dev/null and b/Main.class differ diff --git a/Node.class b/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..16fa445d06d0391dcc0131ba0a8d4fb564ff90c2 Binary files /dev/null and b/Node.class differ diff --git a/base/base/work1/MainTest.class b/base/base/work1/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..81172e28b9c456dd1bd78a3fc85a43a1b90b35ed Binary files /dev/null and b/base/base/work1/MainTest.class differ diff --git a/base/base/work1/MainTest.java b/base/base/work1/MainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..75764aad874f16c688ba2648d2ca8d7d9c9391a3 --- /dev/null +++ b/base/base/work1/MainTest.java @@ -0,0 +1,20 @@ +public class MainTest +{ + public static void main(String args[]){ + //ջij + MyStack myStack = new MyStack(5); + + //myStack.printStack(); + + myStack.push(10); //ѹջ + myStack.push(20); + myStack.push(30); + myStack.push(40); + myStack.push(50); + myStack.printStack(); + + myStack.pop(); //ջջ + myStack.pop(); + myStack.printStack(); + } +} \ No newline at end of file diff --git a/base/base/work1/MyStack.class b/base/base/work1/MyStack.class new file mode 100644 index 0000000000000000000000000000000000000000..50b3d90702f458b9dfa5c08f730803a332b899c2 Binary files /dev/null and b/base/base/work1/MyStack.class differ diff --git a/base/base/work1/MyStack.java b/base/base/work1/MyStack.java new file mode 100644 index 0000000000000000000000000000000000000000..166938693335d810c3597316e37004a9b51f2ba5 --- /dev/null +++ b/base/base/work1/MyStack.java @@ -0,0 +1,54 @@ +public class MyStack +{ + private int[] aStack; + private int maxSize; + private int top = -1; + + public MyStack(int size){ //ջij + maxSize = size; + aStack = new int[maxSize]; + } + + public boolean isEmpty(){ + return top == -1; + } + + public boolean isFull(){ + return top == maxSize-1; + } + + public void push(int value){ + if(isFull()){ + System.out.println("ջˣ"); + return; + } + aStack[++top] = value; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ջǿյģ"); + return; + } + System.out.println(aStack[top--]+""); + } + + public int peek(){ + + if(isEmpty()){ + System.out.println("ջǿյģ"); + } + return aStack[top]; + } + + public void printStack(){ + if(isEmpty()){ + System.out.println("ջ޷ӡ"); + return; + } + for(int i=top ;i>=0 ;i-- ){ + //System.out.printf("aStack[%d]=%d",i,aStack[i]); + System.out.println("aStack["+i+"]="+aStack[i]); + } + } +} \ No newline at end of file diff --git a/base/base/work2/LLStack.class b/base/base/work2/LLStack.class new file mode 100644 index 0000000000000000000000000000000000000000..7364d2742be2649659f494d1dfe81ac8dcb81896 Binary files /dev/null and b/base/base/work2/LLStack.class differ diff --git a/base/base/work2/LLStack.java b/base/base/work2/LLStack.java new file mode 100644 index 0000000000000000000000000000000000000000..3533004b41c32d714947ae027c27a1356e1da9ad --- /dev/null +++ b/base/base/work2/LLStack.java @@ -0,0 +1,86 @@ +public class LLStack{ + StackNode top; + private int count; + private int maxSize; + + public LLStack(){ + } + + public LLStack(int size){ //ջɵĴС + top = null; + count = 0; + maxSize = size; + } + + public boolean isFull(){ + return count == maxSize; + } + + public boolean isEmpty(){ + return count <=0 ; + } + + public void push(int value){ + if(isFull()){ + System.out.println("ջˣ"); + return; + } + StackNode node = new StackNode(value); + if(isEmpty()){ + top = node; + count++; + return; + } + node.next = top; + top = node; + count++; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ջǿյģ"); + return; + } + if(count==1){ + System.out.println("һԪأ"+top.element+""); + top = null; + count--; + return; + } + StackNode temp = new StackNode(); + System.out.println("Ԫأ"+top.element+""); + temp = top; + top = top.next; + temp.next = null; + count--; + } + + public void printLLStack(){ + if(isEmpty()){ + System.out.println("ջ޷ӡ"); + return; + } + System.out.println("ջջף"); + StackNode temp = new StackNode(); + temp = top; + while(temp.next != null){ + System.out.println(temp.element); + System.out.println(" v"); + temp = temp.next; + } + System.out.println(temp.element); + } + + +} +class StackNode{ + int element; + StackNode next; + + public StackNode(int n){ + element = n; + next = null; + } + public StackNode(){ + } +} diff --git a/base/base/work2/MainTest.class b/base/base/work2/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..9bdd46c24fb56a415e5495e2076bb6f7dd6d59ad Binary files /dev/null and b/base/base/work2/MainTest.class differ diff --git a/base/base/work2/MainTest.java b/base/base/work2/MainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4ccc8c2585ecf362f1fe703e2d8b9de5ec9b7033 --- /dev/null +++ b/base/base/work2/MainTest.java @@ -0,0 +1,24 @@ +public class MainTest +{ + public static void main(String args[]){ + //ջij + LLStack llStack = new LLStack(10); + + //myStack.printStack(); + + llStack.push(10); //ѹջ + llStack.push(20); + llStack.push(30); + llStack.push(40); + llStack.push(50); + llStack.printLLStack(); + + llStack.pop(); + llStack.pop(); + llStack.pop(); + llStack.pop(); + llStack.pop(); + llStack.printLLStack(); + + } +} \ No newline at end of file diff --git a/base/base/work2/StackNode.class b/base/base/work2/StackNode.class new file mode 100644 index 0000000000000000000000000000000000000000..daec0574d14f4912bb22c24f25a95eeafd4ea6f6 Binary files /dev/null and b/base/base/work2/StackNode.class differ diff --git a/base/base/work3/Main.class b/base/base/work3/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..56a15f4088efd6861f965527e68aeab6dd598230 Binary files /dev/null and b/base/base/work3/Main.class differ diff --git a/base/base/work3/Main.java b/base/base/work3/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..e6f0ae0ae9602452cd264a980834b5cfee0fef42 --- /dev/null +++ b/base/base/work3/Main.java @@ -0,0 +1,14 @@ +public class Main{ + public static void main(String args[]){ + MyQueue queue = new MyQueue(10); + queue.push(10); + queue.push(20); + queue.push(30); + queue.push(40); + queue.push(50); + queue.printQueue(); + queue.pop(); + queue.pop(); + queue.printQueue(); + } +} \ No newline at end of file diff --git a/base/base/work3/MyQueue.class b/base/base/work3/MyQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..da9377e22e1b1ec47e45a3c08b3f2543104ea53a Binary files /dev/null and b/base/base/work3/MyQueue.class differ diff --git a/base/base/work3/MyQueue.java b/base/base/work3/MyQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..2124f4ace75f6a7228e4140eb8c35481f42fb0ba --- /dev/null +++ b/base/base/work3/MyQueue.java @@ -0,0 +1,55 @@ +public class MyQueue{ + private int count; + private int head; + private int tail; + private int[] arr; + + public MyQueue(){ + } + + public MyQueue(int size){ + arr = new int[size]; + head = 0; + tail = 0; + count = 0; + } + + //---------------------------------------------- + + public boolean isFull(){ + return count == arr.length; + } + + public boolean isEmpty(){ + return count == 0; + } + + public void push(int value){ + if(isFull()){ + System.out.println("Ԫˣ"); + return; + } + count++; + arr[tail++] = value; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ѿ"); + return; + } + int temp = head; + + System.out.println(arr[head]+""); + count--; + head = (head == arr.length - 1 ? head : head+1); + arr[temp]=0; + } + + public void printQueue(){ + for(int i = 0;i <= arr.length-1 ;i++){ + System.out.print(arr[i]+" "); + } + System.out.println(""); + } +} \ No newline at end of file diff --git a/base/base/work4/LLQueue.class b/base/base/work4/LLQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..82de29bcff8c59b3b680e03e1a79c36186925349 Binary files /dev/null and b/base/base/work4/LLQueue.class differ diff --git a/base/base/work4/LLQueue.java b/base/base/work4/LLQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..e7625be8d73c53a2e0c1bb38d7b992536b00d595 --- /dev/null +++ b/base/base/work4/LLQueue.java @@ -0,0 +1,82 @@ +public class LLQueue{ + MyNode head; + MyNode tail; + int count; + int maxSize; + + public LLQueue(){ + } + + public LLQueue(int size){ + maxSize = size; + head = null; + tail = null; + count = 0; + } + + public boolean isFull(){ + return count == maxSize; + } + + public boolean isEmpty(){ + return count == 0; + } + + public void push(int value){ + if(isFull()){ + System.out.println(""); + return; + } + MyNode node = new MyNode(value); + if(count == 0){ + head = node; + tail = node; + count++; + return; + } + tail.next = node; + tail = node; + count++; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ѿ"); + return; + } + if(head == tail){ + head = null; + tail = null; + count--; + return; + } + MyNode temp = head; + head = head.next; + temp = null; + count--; + } + + public void printLLQueue(){ + if(isEmpty()){ + System.out.println("ǿյģ"); + return; + } + MyNode temp = head; + while(temp.next != null){ + System.out.print(temp.element+"-->"); + temp = temp.next; + } + System.out.println(temp.element); + } +} +class MyNode{ + int element; + MyNode next; + + public MyNode(){ + } + + public MyNode(int n){ + element = n; + } +} \ No newline at end of file diff --git a/base/base/work4/Main.class b/base/base/work4/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..6eee07ec1f1c61922c5f14bfea060cad18e16bed Binary files /dev/null and b/base/base/work4/Main.class differ diff --git a/base/base/work4/Main.java b/base/base/work4/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..f492fcc15cfadce333ac5945571a50cda4b0a01e --- /dev/null +++ b/base/base/work4/Main.java @@ -0,0 +1,17 @@ +public class Main{ + public static void main(String args[]){ + LLQueue q = new LLQueue(5); + + q.push(10); + q.push(11); + q.push(12); + q.push(13); + q.push(14); + q.printLLQueue(); + + q.pop(); + q.pop(); + q.pop(); + q.printLLQueue(); + } +} \ No newline at end of file diff --git a/base/base/work4/MyNode.class b/base/base/work4/MyNode.class new file mode 100644 index 0000000000000000000000000000000000000000..aa43a3b9eaa9416e3abfca827ffdf04b49f7bf50 Binary files /dev/null and b/base/base/work4/MyNode.class differ diff --git a/base/work1/MainTest.class b/base/work1/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..81172e28b9c456dd1bd78a3fc85a43a1b90b35ed Binary files /dev/null and b/base/work1/MainTest.class differ diff --git a/base/work1/MainTest.java b/base/work1/MainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..75764aad874f16c688ba2648d2ca8d7d9c9391a3 --- /dev/null +++ b/base/work1/MainTest.java @@ -0,0 +1,20 @@ +public class MainTest +{ + public static void main(String args[]){ + //ջij + MyStack myStack = new MyStack(5); + + //myStack.printStack(); + + myStack.push(10); //ѹջ + myStack.push(20); + myStack.push(30); + myStack.push(40); + myStack.push(50); + myStack.printStack(); + + myStack.pop(); //ջջ + myStack.pop(); + myStack.printStack(); + } +} \ No newline at end of file diff --git a/base/work1/MyStack.class b/base/work1/MyStack.class new file mode 100644 index 0000000000000000000000000000000000000000..50b3d90702f458b9dfa5c08f730803a332b899c2 Binary files /dev/null and b/base/work1/MyStack.class differ diff --git a/base/work1/MyStack.java b/base/work1/MyStack.java new file mode 100644 index 0000000000000000000000000000000000000000..166938693335d810c3597316e37004a9b51f2ba5 --- /dev/null +++ b/base/work1/MyStack.java @@ -0,0 +1,54 @@ +public class MyStack +{ + private int[] aStack; + private int maxSize; + private int top = -1; + + public MyStack(int size){ //ջij + maxSize = size; + aStack = new int[maxSize]; + } + + public boolean isEmpty(){ + return top == -1; + } + + public boolean isFull(){ + return top == maxSize-1; + } + + public void push(int value){ + if(isFull()){ + System.out.println("ջˣ"); + return; + } + aStack[++top] = value; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ջǿյģ"); + return; + } + System.out.println(aStack[top--]+""); + } + + public int peek(){ + + if(isEmpty()){ + System.out.println("ջǿյģ"); + } + return aStack[top]; + } + + public void printStack(){ + if(isEmpty()){ + System.out.println("ջ޷ӡ"); + return; + } + for(int i=top ;i>=0 ;i-- ){ + //System.out.printf("aStack[%d]=%d",i,aStack[i]); + System.out.println("aStack["+i+"]="+aStack[i]); + } + } +} \ No newline at end of file diff --git a/base/work2/LLStack.class b/base/work2/LLStack.class new file mode 100644 index 0000000000000000000000000000000000000000..7364d2742be2649659f494d1dfe81ac8dcb81896 Binary files /dev/null and b/base/work2/LLStack.class differ diff --git a/base/work2/LLStack.java b/base/work2/LLStack.java new file mode 100644 index 0000000000000000000000000000000000000000..3533004b41c32d714947ae027c27a1356e1da9ad --- /dev/null +++ b/base/work2/LLStack.java @@ -0,0 +1,86 @@ +public class LLStack{ + StackNode top; + private int count; + private int maxSize; + + public LLStack(){ + } + + public LLStack(int size){ //ջɵĴС + top = null; + count = 0; + maxSize = size; + } + + public boolean isFull(){ + return count == maxSize; + } + + public boolean isEmpty(){ + return count <=0 ; + } + + public void push(int value){ + if(isFull()){ + System.out.println("ջˣ"); + return; + } + StackNode node = new StackNode(value); + if(isEmpty()){ + top = node; + count++; + return; + } + node.next = top; + top = node; + count++; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ջǿյģ"); + return; + } + if(count==1){ + System.out.println("һԪأ"+top.element+""); + top = null; + count--; + return; + } + StackNode temp = new StackNode(); + System.out.println("Ԫأ"+top.element+""); + temp = top; + top = top.next; + temp.next = null; + count--; + } + + public void printLLStack(){ + if(isEmpty()){ + System.out.println("ջ޷ӡ"); + return; + } + System.out.println("ջջף"); + StackNode temp = new StackNode(); + temp = top; + while(temp.next != null){ + System.out.println(temp.element); + System.out.println(" v"); + temp = temp.next; + } + System.out.println(temp.element); + } + + +} +class StackNode{ + int element; + StackNode next; + + public StackNode(int n){ + element = n; + next = null; + } + public StackNode(){ + } +} diff --git a/base/work2/MainTest.class b/base/work2/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..9bdd46c24fb56a415e5495e2076bb6f7dd6d59ad Binary files /dev/null and b/base/work2/MainTest.class differ diff --git a/base/work2/MainTest.java b/base/work2/MainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..4ccc8c2585ecf362f1fe703e2d8b9de5ec9b7033 --- /dev/null +++ b/base/work2/MainTest.java @@ -0,0 +1,24 @@ +public class MainTest +{ + public static void main(String args[]){ + //ջij + LLStack llStack = new LLStack(10); + + //myStack.printStack(); + + llStack.push(10); //ѹջ + llStack.push(20); + llStack.push(30); + llStack.push(40); + llStack.push(50); + llStack.printLLStack(); + + llStack.pop(); + llStack.pop(); + llStack.pop(); + llStack.pop(); + llStack.pop(); + llStack.printLLStack(); + + } +} \ No newline at end of file diff --git a/base/work2/StackNode.class b/base/work2/StackNode.class new file mode 100644 index 0000000000000000000000000000000000000000..daec0574d14f4912bb22c24f25a95eeafd4ea6f6 Binary files /dev/null and b/base/work2/StackNode.class differ diff --git a/base/work3/Main.class b/base/work3/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..56a15f4088efd6861f965527e68aeab6dd598230 Binary files /dev/null and b/base/work3/Main.class differ diff --git a/base/work3/Main.java b/base/work3/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..e6f0ae0ae9602452cd264a980834b5cfee0fef42 --- /dev/null +++ b/base/work3/Main.java @@ -0,0 +1,14 @@ +public class Main{ + public static void main(String args[]){ + MyQueue queue = new MyQueue(10); + queue.push(10); + queue.push(20); + queue.push(30); + queue.push(40); + queue.push(50); + queue.printQueue(); + queue.pop(); + queue.pop(); + queue.printQueue(); + } +} \ No newline at end of file diff --git a/base/work3/MyQueue.class b/base/work3/MyQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..da9377e22e1b1ec47e45a3c08b3f2543104ea53a Binary files /dev/null and b/base/work3/MyQueue.class differ diff --git a/base/work3/MyQueue.java b/base/work3/MyQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..2124f4ace75f6a7228e4140eb8c35481f42fb0ba --- /dev/null +++ b/base/work3/MyQueue.java @@ -0,0 +1,55 @@ +public class MyQueue{ + private int count; + private int head; + private int tail; + private int[] arr; + + public MyQueue(){ + } + + public MyQueue(int size){ + arr = new int[size]; + head = 0; + tail = 0; + count = 0; + } + + //---------------------------------------------- + + public boolean isFull(){ + return count == arr.length; + } + + public boolean isEmpty(){ + return count == 0; + } + + public void push(int value){ + if(isFull()){ + System.out.println("Ԫˣ"); + return; + } + count++; + arr[tail++] = value; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ѿ"); + return; + } + int temp = head; + + System.out.println(arr[head]+""); + count--; + head = (head == arr.length - 1 ? head : head+1); + arr[temp]=0; + } + + public void printQueue(){ + for(int i = 0;i <= arr.length-1 ;i++){ + System.out.print(arr[i]+" "); + } + System.out.println(""); + } +} \ No newline at end of file diff --git a/base/work4/LLQueue.class b/base/work4/LLQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..82de29bcff8c59b3b680e03e1a79c36186925349 Binary files /dev/null and b/base/work4/LLQueue.class differ diff --git a/base/work4/LLQueue.java b/base/work4/LLQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..e7625be8d73c53a2e0c1bb38d7b992536b00d595 --- /dev/null +++ b/base/work4/LLQueue.java @@ -0,0 +1,82 @@ +public class LLQueue{ + MyNode head; + MyNode tail; + int count; + int maxSize; + + public LLQueue(){ + } + + public LLQueue(int size){ + maxSize = size; + head = null; + tail = null; + count = 0; + } + + public boolean isFull(){ + return count == maxSize; + } + + public boolean isEmpty(){ + return count == 0; + } + + public void push(int value){ + if(isFull()){ + System.out.println(""); + return; + } + MyNode node = new MyNode(value); + if(count == 0){ + head = node; + tail = node; + count++; + return; + } + tail.next = node; + tail = node; + count++; + } + + public void pop(){ + if(isEmpty()){ + System.out.println("ѿ"); + return; + } + if(head == tail){ + head = null; + tail = null; + count--; + return; + } + MyNode temp = head; + head = head.next; + temp = null; + count--; + } + + public void printLLQueue(){ + if(isEmpty()){ + System.out.println("ǿյģ"); + return; + } + MyNode temp = head; + while(temp.next != null){ + System.out.print(temp.element+"-->"); + temp = temp.next; + } + System.out.println(temp.element); + } +} +class MyNode{ + int element; + MyNode next; + + public MyNode(){ + } + + public MyNode(int n){ + element = n; + } +} \ No newline at end of file diff --git a/base/work4/Main.class b/base/work4/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..6eee07ec1f1c61922c5f14bfea060cad18e16bed Binary files /dev/null and b/base/work4/Main.class differ diff --git a/base/work4/Main.java b/base/work4/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..f492fcc15cfadce333ac5945571a50cda4b0a01e --- /dev/null +++ b/base/work4/Main.java @@ -0,0 +1,17 @@ +public class Main{ + public static void main(String args[]){ + LLQueue q = new LLQueue(5); + + q.push(10); + q.push(11); + q.push(12); + q.push(13); + q.push(14); + q.printLLQueue(); + + q.pop(); + q.pop(); + q.pop(); + q.printLLQueue(); + } +} \ No newline at end of file diff --git a/base/work4/MyNode.class b/base/work4/MyNode.class new file mode 100644 index 0000000000000000000000000000000000000000..aa43a3b9eaa9416e3abfca827ffdf04b49f7bf50 Binary files /dev/null and b/base/work4/MyNode.class differ diff --git a/syh/1212.java b/syh/1212.java new file mode 100644 index 0000000000000000000000000000000000000000..c32a793ff785a08bad00be77c45365d3790a1f5b --- /dev/null +++ b/syh/1212.java @@ -0,0 +1,189 @@ +public class LinkedList { + + Node first; + Node last; + int size = 0; + + + public LinkedList() { + + } + + public LinkedList(String s) { + Node newNode = new Node(null, null, s); + first = newNode; + last = newNode; + size++; + } + + + public void add(String s) { + Node newNode = new Node(null, null, s); + if (size == 0) { + first = newNode; + last = newNode; + } else if (size == 1) { + last = newNode; + first.next = last; + last.perv = first; + } else {//其余情况 + Node temp = last; + last = newNode; + temp.next = last; + last.perv = temp; + } + size++; + } + + public void firstAdd(String s) { + Node newNode = new Node(null, null, s); + newNode.next = first; + first.perv = newNode; + first = newNode; + size++; + } + + public void lastAdd(String s) { + Node newNode = new Node(null, null, s); + newNode.perv = last; + last.next = newNode; + last = newNode; + size++; + } + +/* + public void insert(String s, int index) { + if (index == 1) { + firstAdd(s); + } else if (index == size) { + lastAdd(s); + } else { + Node newNode = new Node(null, null, s); + Node node = jump(index); + newNode.perv = node.perv; + newNode.next = node; + node.perv.next = newNode; + node.perv = newNode; + size++; + } + } + + public void delete(int position) { + Node node = jump(position); + node.perv.next = node.next; + node.next.perv = node.perv; + size--; + } + + public boolean findItem(String s) { + Node node = first; + for (int i = 1; i < size; i++) { + if (node.s.equals(s)) { + return true; + } else { + node = node.next; + } + } + return false; + } + + + public void copy(LinkedList linkedList) { + LinkedList list = new LinkedList(); + Node nowNode = linkedList.first; + for (int i = 1; i < linkedList.size; i++) { + list.add(nowNode.s); + } + clone(list); + } + + + public void clone(LinkedList linkedList) { + last.next = linkedList.first; + linkedList.first.perv = last; + last = linkedList.last; + size+=linkedList.size; + } + + + public Node jump(int position) { + if (position <= size && position > 0) { + Node node = first; + for (int i = 1; i < position; i++) { + node = node.next; + } + return node; + } else { + System.out.println("error..."); + } + return null; + } + + public Node find() { + if (size == 1) { + System.out.println("没有中间节点"); + } else if (size == 0) { + System.out.println("链表为空"); + } else { + if (size % 2 == 0) { + System.out.println("没有中间节点"); + } else { + return jump((size / 2) + 1); + } + } + return null; + } + + public void fz() { + LinkedList list = new LinkedList(); + for (int i = size; i >= 1; i--) { + list.add(jump(i).s); + } + first = list.first; + last = list.last; + } + + public int getSize() { + return size; + } +*/ + + + @Override + public String toString() { + Node node = first; + System.out.print("{"); + for (int i = 1; i <= size; i++) { + System.out.print(node.s); + System.out.print(", "); + node = node.next; + } + //System.out.print("}"); + return "}"; + } + + /* + static class Node { + private Node perv; + private Node next; + private String s; + + public Node(Node perv, Node next, String s) { + this.perv = perv; + this.next = next; + this.s = s; + } + } +*/ +} +class Node{ + Node perv; + Node next; + String s; + + public Node(Node perv, Node next, String s) { + this.perv = perv; + this.next = next; + this.s = s; + } +} diff --git a/syh/LinkedList.class b/syh/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..a02a97b5689852c73e48cc62add84940a201ee53 Binary files /dev/null and b/syh/LinkedList.class differ diff --git a/syh/MainTest.class b/syh/MainTest.class new file mode 100644 index 0000000000000000000000000000000000000000..20c8b32bfc8309cdb8d7fd8a5f542fa232a8c409 Binary files /dev/null and b/syh/MainTest.class differ diff --git a/syh/MainTest.java b/syh/MainTest.java new file mode 100644 index 0000000000000000000000000000000000000000..2eb22119377207de68f830c054c14f6e66409e21 --- /dev/null +++ b/syh/MainTest.java @@ -0,0 +1,8 @@ +public class MainTest { + public static void main(String[] args) { + LinkedList ll = new LinkedList(); + ll.add("A"); + ll.add("B"); + System.out.println(ll); + } +} \ No newline at end of file diff --git a/syh/Node.class b/syh/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..eec565844b8bbf1e412e75d3d1b764dbf09bc58f Binary files /dev/null and b/syh/Node.class differ