Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
648 B
4
Indexable
Never
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;
	}
Leave a Comment