Untitled

 avatar
unknown
plain_text
2 years ago
648 B
7
Indexable
public class Stack {
	
	char A[];
	int top = -1;
	int size;
	
	Stack(int size){
		this.size = size;
		this.A = new char[size];
	}
	
	void push(char insert){
		if (this.top == this.size - 1){
			System.out.println("Stack over flow");
		}
		else{
			this.top += 1;
			this.A[this.top] = insert;
		}
	}
	
	char peek(){
		if (this.top == -1){
			System.out.println("Stack Underflow");
			return 'n';
		}
		else{
			return this.A[this.top];
		}
	}
	
	void pop(){
		if (this.top == -1){
			System.out.println("Stack Underflow");
		}
		else{
			this.top--;
		}
	}
	
	boolean isEmpty(){
		return this.top == -1;
	}
Editor is loading...
Leave a Comment