Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

precedence and operators #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
class Stack {
private:
vector<T> data;

public:
bool empty() const {
return data.empty();
}

size_t size() const {
return data.size();
}

T& top() {
if (empty()) {
throw std::runtime_error("Stack is empty.");
}
return data.back();
}

const T& top() const {
if (empty()) {
throw std::runtime_error("Stack is empty.");
}
return data.back();
}

void push(const T& value) {
data.push_back(value);
}

void pop() {
if (empty()) {
throw std::runtime_error("Stack is empty.");
}
data.pop_back();
}
};
int precedence(char op) {
if (op == '+' || op == '-')
return 1;
if (op == '*' || op == '/')
return 2;
if (op == '^')
return 3;
return 0;
}

bool is_operator(char c) {
return c == '+' || c == '-' || c == '*' || c == '/' || c == '^' || c == '!' ||
c == 's' || c == 'c' || c == 't' || c == 'l' || c == 'q' || c == 'x';
}

int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}