diff --git "a/\344\275\234\344\270\232/ArrayStack.java" "b/\344\275\234\344\270\232/ArrayStack.java" new file mode 100644 index 0000000000000000000000000000000000000000..f1cd3f9d5790c17316b8fcd1c29a46a13f4d3a38 --- /dev/null +++ "b/\344\275\234\344\270\232/ArrayStack.java" @@ -0,0 +1,55 @@ +public class ArrayStack{ + private long[] a; + private int size; + private int top; + public ArrayStack(int maxSize){ + this.size=maxSize; + this.a=new long[size]; + this.top=-1; + } + + public void push(long value){ + if(isFull()){ + System.out.println("栈已经满了"); + return; + } + ++top; + } + + public void peeek(){ + if(isEmpty()){ + System.out.println("栈中没有元素"); + } + System.out.println(a[top]); + } + + public long pop(){ + if(isEmpty()){ + System.out.println("栈中没有元素"); + } + System.out.println(a[top--]); + } + + public int size(){ + return top+1; + } + + public boolean isEmpty(){ + return (top==-1); + } + + public boolean isFull(){ + return (top==size-1); + } + + public void display(){ + System.out.print("["); + for(int i=top;i>=0;i--){ + System.out.print(a[i]); + if(i!=0){ + System.out.print(","); + } + } + System.out.println("]"); + } +} \ No newline at end of file diff --git "a/\344\275\234\344\270\232/ArrayToQueue1.java" "b/\344\275\234\344\270\232/ArrayToQueue1.java" new file mode 100644 index 0000000000000000000000000000000000000000..7fe7f3c8e53a29355f043e4933cf2d413ab9aaa7 --- /dev/null +++ "b/\344\275\234\344\270\232/ArrayToQueue1.java" @@ -0,0 +1,33 @@ +class ArrayToQueue1{ + private int maxSize; + private int front; + private int rear; + private int arr[]; + public boolean isFull(){ + return rear==maxSize-1; + } + public boolean isEmpty(){ + return rear==front; + } + public void addNumber(int num){ + if(isFull()){ + System.out.println("队列已经满了"); + } + rear++; + arr[rear]=num; + } + public void getNumber(){ + if(isEmpty()){ + System.out.println("队列没有数据"); + } + front++; + return arr[front]; + } + public int headNumber(){ + if(isEmpty()){ + System.out.println("队列没有数据"); + } + return [front+1]; + } +} + diff --git "a/\344\275\234\344\270\232/LinkedQueue.java" "b/\344\275\234\344\270\232/LinkedQueue.java" new file mode 100644 index 0000000000000000000000000000000000000000..2871c0c0dd6208899b42fa7228b5955a70b026cf --- /dev/null +++ "b/\344\275\234\344\270\232/LinkedQueue.java" @@ -0,0 +1,30 @@ +public class LinkedQueue{ + Node front; + Node rear; + int size=0; + public boolean isEmpty(){ + return size==0 ? true:false; + } + public boolean addQueue(){ + if(size==0){ + front=new Node; + rear=rear+1; + size++; + return true; + } + Node s=new Node(); + rear=s; + size++; + return true; + } + public boolean deleteQueue(){ + if(isEmpty()){ + System.out.println("当前队列没有元素"); + return false; + } + front=front.next; + size--; + return true; + } + +} \ No newline at end of file diff --git "a/\344\275\234\344\270\232/Linkedstack.java" "b/\344\275\234\344\270\232/Linkedstack.java" new file mode 100644 index 0000000000000000000000000000000000000000..9fd74ab9e38bd3b36727f2247ffd6e80c441e3bd --- /dev/null +++ "b/\344\275\234\344\270\232/Linkedstack.java" @@ -0,0 +1,48 @@ +class Linkedstack{ + private Node top; + private int size; + public LinkedStack(){ + top=null; + size=0; + } + public boolean isEmpty(){ + return size==0; + } + public void clear(){ + top=null; + size=0; + } + public int length(){ + return size; + } + private class Node{ + Node pre; + T data; + public Node(T data){ + this.data=data; + } + } + public boolean push(t data){ + Node node=new Node(data); + node.pre=top; + top=node; + size++; + return true; + } + public T pop(){ + if(top!=null){ + Node node=top; + top=top.pre; + size--; + return node.data; + } + return null; + } + public T peek(){ + if(top!=null){ + return top.data; + } + return null; + } + +} \ No newline at end of file