If you still want the Stack-based method in the same file, you can put it below this one without interfering, but they must be separate methods inside the class, not nested.
Do you want me to put both versions together without brace mistakes so you can copy-paste directly? That will also avoid the “illegal start of expression” error completely.