Java Programs XII 802
Java Programs XII 802
void display(String b) {
System.out.println("String: " + b);
}
}
Stack(int size) {
arr = new int[size];
capacity = size;
top = -1;
}
void push(int x) {
if (top == capacity - 1) {
System.out.println("Stack Overflow");
return;
}
arr[++top] = x;
}
void pop() {
if (top == -1) {
System.out.println("Stack Underflow");
return;
}
top--;
}
int peek() {
return arr[top];
}
}
Queue(int size) {
arr = new int[size];
capacity = size;
front = rear = 0;
}
void enqueue(int x) {
if (rear == capacity) {
System.out.println("Queue Overflow");
return;
}
arr[rear++] = x;
}
void dequeue() {
if (front == rear) {
System.out.println("Queue Underflow");
return;
}
front++;
}
int peek() {
return arr[front];
}
}
MyClass(int value) {
this.value = value;
}
void display() {
System.out.println(value);
}
}