#include <iostream>
using namespace std;
class TwoStacksOneArray {
private:
int* arr;
int size;
int evenIndex;
int oddIndex;
public:
TwoStacksOneArray(int n) {
size = n;
arr = new int[size];
evenIndex = 0;
oddIndex = 1;
for (int i = 0; i < size; i++) {
arr[i] = -1;
void push(int value) {
if (value % 2 == 0) {
if (evenIndex < size) {
arr[evenIndex] = value;
evenIndex += 2;
} else {
cout << "Even Stack Overflow!" << endl;
}
} else {
if (oddIndex < size) {
arr[oddIndex] = value;
oddIndex += 2;
} else {
cout << "Odd Stack Overflow!" << endl;
void popEven() {
if (evenIndex > 0) {
evenIndex -= 2;
cout << "Popped from Even Stack: " << arr[evenIndex] << endl;
arr[evenIndex] = -1;
} else {
cout << "Even Stack Underflow!" << endl;
void popOdd() {
if (oddIndex > 1) {
oddIndex -= 2;
cout << "Popped from Odd Stack: " << arr[oddIndex] << endl;
arr[oddIndex] = -1;
} else {
cout << "Odd Stack Underflow!" << endl;
}
void display() {
cout << "Array: [ ";
for (int i = 0; i < size; i++) {
if (arr[i] != -1) {
cout << arr[i] << " ";
} else {
cout << "_ ";
cout << "]" << endl;
~TwoStacksOneArray() {
delete[] arr;
};
int main() {
cout << "IBRAHIM AHMAD 231571" << endl;
TwoStacksOneArray stacks(10);
stacks.push(2);
stacks.push(5);
stacks.push(4);
stacks.push(7);
stacks.display();
stacks.popEven();
stacks.popOdd();
stacks.display();
return 0;