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

What about this implementation of pop() for Stack? #73

Open
SolKuczala opened this issue Mar 14, 2024 · 1 comment
Open

What about this implementation of pop() for Stack? #73

SolKuczala opened this issue Mar 14, 2024 · 1 comment

Comments

@SolKuczala
Copy link

SolKuczala commented Mar 14, 2024

I'm following your course (thanks for it, it's helping me a lot), and I'm following the implementations along and, while doing the pop() method for the Stack class, I got stuck with the proposed implementation and, I came up with this implementation instead, that passed your tests:

pop(): T | undefined {
        if (!this.head) {
            return undefined;
        }
        this.length--
        const temp = this.head
        this.head = this.head.prev
        
        return temp.value
    }

What would be the difference with yours? Am I missing something? Thank you :)

@EnzoKACI
Copy link

EnzoKACI commented Apr 1, 2024

had a similar issue, though your code did not work for me
actually rolled back to version seen in the proposed implementation
then found the issue actually came from the pushing part where I was missing the correct node.prev udpate
as the tests are not independant (ie they push elements then check if they popped out in the right order) you might get undefined wrongly for elements that should have been defined in the previous tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants