diff --git a/Main.class b/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..a91cd38b67c453b1f78d5941e69da1122e074132 Binary files /dev/null and b/Main.class differ diff --git a/Main.java b/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..664a82a7d095562ba6577a4144bb2e67716b8ce2 --- /dev/null +++ b/Main.java @@ -0,0 +1,12 @@ +class Main{ + public static void main(String[] args) { + Stack s=new Stack(3); + s.push(2); + s.push(4); + s.push(6); + System.out.println(s.pop()); + System.out.println(s.peek()); + //s.push(8); + s.showAll(); + } +} \ No newline at end of file diff --git a/Stack.class b/Stack.class new file mode 100644 index 0000000000000000000000000000000000000000..87cf36f302824ab7ef5437ccb21b28d046460006 Binary files /dev/null and b/Stack.class differ diff --git a/Stack-pseudocode.java b/Stack.java old mode 100755 new mode 100644 similarity index 52% rename from Stack-pseudocode.java rename to Stack.java index 567e476a49db224bf4e0ca6d1b6a495795afec47..5c897d956a334b95b1f11650b7494f9b5b09dd66 --- a/Stack-pseudocode.java +++ b/Stack.java @@ -1,42 +1,46 @@ -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){ + this.size = size; + stack = new int[size]; + top = -1; + } + + + public void push(int item){ + if(top >= size ){ + System.out.println("StackOverflowError"); + } + + stack[++top] = item; + } + + + public int pop(){ + if(top <=0 ){ + System.out.println("StackEmpty"); + } + + return stack[top--]; + + } + + public int peek(){ + + if(top <=0 ){ + System.out.println("StackEmpty"); + } + return stack[top-1]; + } + + public void showAll(){ + for(int i=top;i>=0;i--){ + System.out.print(" "+stack[i]); + } + } +} + + diff --git a/duilie/Main.class b/duilie/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..8d3b9141b9c6358b9ce4af3f890bb386b61f8b51 Binary files /dev/null and b/duilie/Main.class differ diff --git a/duilie/Main.java b/duilie/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..fa311a96209ddd68fe45871edc8dbe2bbd261715 --- /dev/null +++ b/duilie/Main.java @@ -0,0 +1,10 @@ +class Main{ + public static void main(String[] args) { + MyQueue m=new MyQueue(4); + m.Queue_Push(1); + m.Queue_Push(2); + m.Queue_Push(3); + m.Queue_Poll(); + System.out.println(m.Queue_peek()); + } +} \ No newline at end of file diff --git a/duilie/MyQueue.class b/duilie/MyQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..83eb72aa14dd86ac28ecb66fb69386823e63cc04 Binary files /dev/null and b/duilie/MyQueue.class differ diff --git a/duilie/MyQueue.java b/duilie/MyQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..e726979eb057ac8153b4413c520398bd1fc77af9 --- /dev/null +++ b/duilie/MyQueue.java @@ -0,0 +1,37 @@ +public class MyQueue { + private int [] arr; + private int start; + private int end; + private int size; + + MyQueue(int initsize){ + arr=new int[initsize]; + start=0; + end=0; + size=0; + } + public void Queue_Push(int item){ + arr[end]=item; + end=end==arr.length-1?0:end+1; + size++; + } + public Integer Queue_peek(){ + return arr[start]; + } + + public int Queue_Poll() { + if (size == 0) { + System.out.println("The queue is empty"); + } + int tmp = start; + start = start == arr.length - 1 ? 0 : start + 1; + size--; + return arr[tmp]; + } + public void Queue_Print() { + + } + +} + + diff --git a/duilie2/Main.class b/duilie2/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..6e20e3c2142a2e9128fcef8c164c546a25cb2458 Binary files /dev/null and b/duilie2/Main.class differ diff --git a/duilie2/Main.java b/duilie2/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..55a5c512a06dacb0ce37c2e894ec1d3e4b999c30 --- /dev/null +++ b/duilie2/Main.java @@ -0,0 +1,12 @@ +class Main{ + public static void main(String[] args) { + MyQueue m=new MyQueue(); + m.Queue_add(1); + m.Queue_add(2); + m.Queue_add(3); + m.Queue_del(); + m.Queue_del(); + m.print(); + System.out.println(m.Queue_Len()); + } +} \ No newline at end of file diff --git a/duilie2/MyQueue.class b/duilie2/MyQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..c5f47ec4550935a454ad199b47df04f116fd8f8d Binary files /dev/null and b/duilie2/MyQueue.class differ diff --git a/duilie2/MyQueue.java b/duilie2/MyQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..2d5de1301f6c77a8619dde00ae6f92ca7dc47a22 --- /dev/null +++ b/duilie2/MyQueue.java @@ -0,0 +1,50 @@ +public class MyQueue{ + private Node head; + private Node rear; + private int size; + + public MyQueue(){ + head=null; + rear=null; + } + public boolean isempty(){ + return size==0? true:false; + } + public boolean Queue_add(int item){ + if(size==0){ + head=new Node(item); + rear=head; + size++; + return true; + }else{ + Node tep=new Node(item); + rear.next=tep; + rear=tep; + size++; + return true; + } + } + + public void Queue_del(){ + if(isempty()){ + System.out.println("队列为空"); + } + head=head.next; + size--; + } + + public Integer Queue_Len(){ + return size; + } + 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/duilie2/Node.class b/duilie2/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..a383363383e004072772b0293411ecf05b408603 Binary files /dev/null and b/duilie2/Node.class differ diff --git a/duilie2/Node.java b/duilie2/Node.java new file mode 100644 index 0000000000000000000000000000000000000000..f88ee4ffe6d5fc0f14b539955906087f6eeadfd1 --- /dev/null +++ b/duilie2/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/lianbiao/LinkedList.class b/lianbiao/LinkedList.class new file mode 100644 index 0000000000000000000000000000000000000000..b5514c6f90f98a052959944abf149aa136c08e59 Binary files /dev/null and b/lianbiao/LinkedList.class differ diff --git a/lianbiao/LinkedList.java b/lianbiao/LinkedList.java new file mode 100644 index 0000000000000000000000000000000000000000..73a23a429a4f1d5455a38813d87b34e9c15896ec --- /dev/null +++ b/lianbiao/LinkedList.java @@ -0,0 +1,48 @@ +public class LinkedList { + private Node head; + private Node rear; + public int top; + private int size; + + public LinkedList(int size){ + head=null; + rear=null; + top=0; + this.size=size; + } + public void Stack_Push(int item){ + if(top >= size ){ + System.out.println("StackOverflowError"); + } + if(top==0){ + Node tep=new Node(item); + head=tep; + rear=tep; + }else{ + Node tep=new Node(item); + tep.next=head; + head=tep; + } + top++; + } + public Object Stack_Pop(){ + head=head.next; + top--; + return head.item; + } + + public Object Stack_Peek(){ + return head.item; + } + 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/lianbiao/Main.class b/lianbiao/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..f7072ea787e75c76965a37341ac461c4dfc53d53 Binary files /dev/null and b/lianbiao/Main.class differ diff --git a/lianbiao/Main.java b/lianbiao/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..35987202d1c9643d00caea493cac5474415ab5b4 --- /dev/null +++ b/lianbiao/Main.java @@ -0,0 +1,12 @@ +class Main{ + public static void main(String[] args) { + LinkedList ll = new LinkedList(3); + ll.Stack_Push(1); + ll.Stack_Push(2); + ll.Stack_Push(3); + ll.Stack_Push(4); + System.out.println(ll.Stack_Pop()); + System.out.println(ll.Stack_Peek()); + ll.print(); + } +} \ No newline at end of file diff --git a/lianbiao/Node.class b/lianbiao/Node.class new file mode 100644 index 0000000000000000000000000000000000000000..a383363383e004072772b0293411ecf05b408603 Binary files /dev/null and b/lianbiao/Node.class differ diff --git a/lianbiao/Node.java b/lianbiao/Node.java new file mode 100644 index 0000000000000000000000000000000000000000..f88ee4ffe6d5fc0f14b539955906087f6eeadfd1 --- /dev/null +++ b/lianbiao/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