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

[C++] BOJ10845 (Stack) #14

Open
Settpark opened this issue Sep 23, 2021 · 0 comments
Open

[C++] BOJ10845 (Stack) #14

Settpark opened this issue Sep 23, 2021 · 0 comments
Assignees
Labels
Algorithm Algorithm C++ C++

Comments

@Settpark
Copy link
Owner

스택의 구현

  • 크게 어려운 부분은 없었으나
    int MX = 1000005;
    int data[MX];
    
    int head = 0, tail = 0;

    if (command == "back") {
        if (tail - head != 0) cout << data[tail-1] << '\n';
        else cout << -1 << '\n';
    }
  • 가장 마지막 원소에 접근할 때는 tail-1이다!
  • tail은 항상 마지막 원소 다음을 가리키고 있기 때문에 값이 비어있다. (혹은 쓰레기값이 들어있지렁이)
@Settpark Settpark added Algorithm Algorithm C++ C++ labels Sep 23, 2021
@Settpark Settpark self-assigned this Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algorithm Algorithm C++ C++
Projects
None yet
Development

No branches or pull requests

1 participant