Dsa Lab
Dsa Lab
Dsa Lab
class TwoStacksOneArray {
private:
int* arr;
int size;
int evenIndex;
int oddIndex;
public:
TwoStacksOneArray(int n) {
size = n;
evenIndex = 0;
oddIndex = 1;
arr[i] = -1;
if (value % 2 == 0) {
arr[evenIndex] = value;
evenIndex += 2;
} else {
}
} else {
arr[oddIndex] = value;
oddIndex += 2;
} else {
void popEven() {
if (evenIndex > 0) {
evenIndex -= 2;
cout << "Popped from Even Stack: " << arr[evenIndex] << endl;
arr[evenIndex] = -1;
} else {
void popOdd() {
if (oddIndex > 1) {
oddIndex -= 2;
cout << "Popped from Odd Stack: " << arr[oddIndex] << endl;
arr[oddIndex] = -1;
} else {
}
void display() {
if (arr[i] != -1) {
} else {
~TwoStacksOneArray() {
delete[] arr;
};
int main() {
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;