Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
1.3 kB
1
Indexable
Never
#include <iostream>
#include <stack>

class Stack {
private:
    std::stack<char> items;

public:
    bool isEmpty() {
        return items.empty();
    }

    void push(char item) {
        items.push(item);
    }

    char pop() {
        char item = '\0'; // Default value for an empty stack
        if (!isEmpty()) {
            item = items.top();
            items.pop();
        }
        return item;
    }

    char peek() {
        char item = '\0'; // Default value for an empty stack
        if (!isEmpty()) {
            item = items.top();
        }
        return item;
    }

    int size() {
        return items.size();
    }
};

Stack loadstack(int upper = 0) {
    Stack stack;
    char start = (upper == 1) ? 'A' : 'a';
    char end = (upper == 1) ? 'Z' : 'z';

    for (char ch = start; ch <= end; ++ch) {
        stack.push(ch);
    }

    return stack;
}

int main() {
    Stack lowercaseStack = loadstack();
    Stack uppercaseStack = loadstack(1);

    // Test the stacks
    while (!lowercaseStack.isEmpty()) {
        std::cout << lowercaseStack.pop() << " ";
    }
    std::cout << std::endl;

    while (!uppercaseStack.isEmpty()) {
        std::cout << uppercaseStack.pop() << " ";
    }
    std::cout << std::endl;

    return 0;
}