From ff830900d87a9135fe2edd7b448348ceecbb5c77 Mon Sep 17 00:00:00 2001 From: hui <1379593215@qq.com> Date: Tue, 17 Nov 2020 22:22:38 +0800 Subject: [PATCH] =?UTF-8?q?11=E6=9C=8817=E5=8F=B7=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LinkQueue.java | 4 ++ Main.java | 4 ++ Mystack.java | 7 +++ Node.java | 8 +++ QueueNode.java | 4 ++ QueueTest.java | 4 ++ Stack-pseudocode.java => Stack.java | 84 ++++++++++++++--------------- 7 files changed, 73 insertions(+), 42 deletions(-) create mode 100644 LinkQueue.java create mode 100644 Main.java create mode 100644 Mystack.java create mode 100644 Node.java create mode 100644 QueueNode.java create mode 100644 QueueTest.java rename Stack-pseudocode.java => Stack.java (93%) mode change 100755 => 100644 diff --git a/LinkQueue.java b/LinkQueue.java new file mode 100644 index 0000000..238c04a --- /dev/null +++ b/LinkQueue.java @@ -0,0 +1,4 @@ +package PACKAGE_NAME; + +public class LinkQueue { +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..1e936b3 --- /dev/null +++ b/Main.java @@ -0,0 +1,4 @@ +package PACKAGE_NAME; + +public class Main { +} diff --git a/Mystack.java b/Mystack.java new file mode 100644 index 0000000..9d8fa37 --- /dev/null +++ b/Mystack.java @@ -0,0 +1,7 @@ +public class Mystack { + private Node head; + + public Mystack() { + head = null; + } +} \ No newline at end of file diff --git a/Node.java b/Node.java new file mode 100644 index 0000000..fe64454 --- /dev/null +++ b/Node.java @@ -0,0 +1,8 @@ +public class Node { + E item; + Node next = null; + + Node(E item) { + this.item = item; + } +} \ No newline at end of file diff --git a/QueueNode.java b/QueueNode.java new file mode 100644 index 0000000..fa0b3da --- /dev/null +++ b/QueueNode.java @@ -0,0 +1,4 @@ +package PACKAGE_NAME; + +public class QueueNode { +} diff --git a/QueueTest.java b/QueueTest.java new file mode 100644 index 0000000..b5d1085 --- /dev/null +++ b/QueueTest.java @@ -0,0 +1,4 @@ +package PACKAGE_NAME; + +public class QueueTest { +} diff --git a/Stack-pseudocode.java b/Stack.java old mode 100755 new mode 100644 similarity index 93% rename from Stack-pseudocode.java rename to Stack.java index 567e476..27eb982 --- a/Stack-pseudocode.java +++ b/Stack.java @@ -1,42 +1,42 @@ -public class Stack { - public int[] stack; - public int top; - private int size; - - Stack(int size){ - // 构建一个长度为size大小的空数组来模拟栈 - this.size = size; - stack = new int[size]; - top = 0; // top永远指向下一个可放入的位置 - } - - - public void push(int item){ - if(top >= size ){ - throw new Exception("StackOverflowError"); - } - - stack[top] = item; - top++; - } - - - public int pop(){ - if(top <=0 ){ - throw new Exception("StackEmpty"); - } - - return stack[top--]; - - } - - public int peek(){ - - if(top <=0 ){ - throw new Exception("StackEmpty"); - } - return stack[top-1]; - } -} - - +public class Stack { + public int[] stack; + public int top; + private int size; + + Stack(int size){ + // 构建一个长度为size大小的空数组来模拟栈 + this.size = size; + stack = new int[size]; + top = 0; // top永远指向下一个可放入的位置 + } + + + public void push(int item){ + if(top >= size ){ + throw new Exception("StackOverflowError"); + } + + stack[top] = item; + top++; + } + + + public int pop(){ + if(top <=0 ){ + throw new Exception("StackEmpty"); + } + + return stack[top--]; + + } + + public int peek(){ + + if(top <=0 ){ + throw new Exception("StackEmpty"); + } + return stack[top-1]; + } +} + + -- Gitee