diff --git "a/\351\230\237\345\210\227/MyStack.java" "b/\351\230\237\345\210\227/MyStack.java" new file mode 100644 index 0000000000000000000000000000000000000000..c1377b795f277043bc9ee161d0b8fa19d06de7cc --- /dev/null +++ "b/\351\230\237\345\210\227/MyStack.java" @@ -0,0 +1,48 @@ + +public class MyStack { + private int maxSize; + private long[] stackArray; + private int top; + + public MyStack(int s) { + maxSize = s; + stackArray = new long[maxSize]; + top = -1; + } + + public void push(long j) { + stackArray[++top] = j; + } + + public long pop() { + return stackArray[top--]; + } + + public long peek() { + return stackArray[top]; + } + + public boolean isEmpty() { + return (top == -1); + } + + public boolean isFull() { + return (top == maxSize - 1); + } + + public static void main(String[] args) { + MyStack theStack = new MyStack(10); + theStack.push(10); + theStack.push(20); + theStack.push(30); + theStack.push(40); + theStack.push(50); + while (!theStack.isEmpty()) { + long value = theStack.pop(); + System.out.print(value); + System.out.print(" "); + } + System.out.println(""); + } +} + diff --git "a/\351\230\237\345\210\227/Stack-pseudocode.java" "b/\351\230\237\345\210\227/Stack-pseudocode.java" new file mode 100644 index 0000000000000000000000000000000000000000..27eb9820d960cafc293ff45ee50fe36fc0fa95fb --- /dev/null +++ "b/\351\230\237\345\210\227/Stack-pseudocode.java" @@ -0,0 +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]; + } +} + + diff --git "a/\351\230\237\345\210\227/\351\230\237\345\210\227.java" "b/\351\230\237\345\210\227/\351\230\237\345\210\227.java" new file mode 100644 index 0000000000000000000000000000000000000000..d8818b4aec5a459ed0760842b62e9c86cc346843 --- /dev/null +++ "b/\351\230\237\345\210\227/\351\230\237\345\210\227.java" @@ -0,0 +1,22 @@ +package Test; +import java.util.*; +public class 队列{ + + public static void main(String[] args) { + // TODO 自动生成的方法存根 + // 输入与字符处理 + Scanner scanner=new Scanner(System.in); + String string=scanner.nextLine(); + String [] string2=string.split(""); + + //创建队列,并且将字符串插入队列里面 + Queue queue=new LinkedList(); + for(int i=0;i