数据结构四插入排序&栈
插入排序:选取一个元素,在其前面选择适当的位置插入。
// 插入排序public void insertSort() {long select = 0L;for(int i = 1; i < elems; i++) {select = arr[i];int j = 0;for(j = i;j > 0 && arr[j - 1] >= select; j--) {arr[j] = arr[j - 1];}arr[j] = select;}}
public class MyStack {private int maxSize;private long[] arr;private int top;// 构造方法public MyStack(int size) {maxSize = size;arr = new long[maxSize];top = -1;}// 压入数据public void push(long value){arr[++top]=value;}// 弹出数据public long pop() {return arr[top--];}// 访问栈顶元素public long peek() {return arr[top];}// 栈是否为空public boolean isEmpty() {return (top == -1);}// 栈是否满了public boolean isFull() {return (top == maxSize - 1);}}[/color][/size]