Ouput:
SimpleStack.java
Java Core 2017
package com.array; /** * Created by Antonio 11/06/17. */ public class SimpleStack { char charr[] = new char[5]; int top = -1; public boolean isEmpty() { if (charr[0] == '\0') { return true; } return false; } public boolean isFull() { if (charr.length == top) { return true; } else { return false; } } public void push(char ch) { if (!isFull()) { top++; charr[top] = ch; } else { System.out.println("stack is full"); } } public char pop() { char chh = charr[top]; if (!isEmpty()) { charr[top] = '\0'; top--; } else { System.out.println("stack is empty"); } return chh; } public void display() { System.out.println(); for (int i = 0; i < charr.length; i++) { System.out.printf("\t -->" + charr[i]); } } public static void main(String[] args) { SimpleStack simpleStack = new SimpleStack(); // simpleStack.pop(); simpleStack.push('a'); simpleStack.push('b'); simpleStack.push('c'); simpleStack.push('d'); simpleStack.push('e'); simpleStack.display(); simpleStack.pop(); simpleStack.push('F'); simpleStack.display(); } }
0 nhận xét:
Post a Comment