I recently lost out on a great job because I couldn't pass the coding challenge. I was given a header file that I COULD NOT modify, and asked to fill it out with a stack with a linked list backbone. The problem was to reverse stack data (integers) such that nodes 1..4 contained 1, 2, 3, 4, and the output would be 4, 3, 2, 1. I easily wrote this, with one problem: none of the methods in the class signatures contained any output method other than top(), which returned the top node. Everything else was a void method. So I modified the size() method t]such that it output the values of each node.
I believe this is where I failed. The code contained a "node" method with a data member and a pointer to the next node. The stack class had a pop method, a push method, that size method, top, and that's about it. Both were templates. Other than adding a friend class or resorting to dirty pointer tricks, I could not figure out how to display the data members of the node class.
I really don't understand how this is a valid problem to pose.
I am wondering if you overthought this. Looking at the file it doesn't say that you can't include other include files such as iostream where you could easily output your list from your main.cpp file. See: ."...then add a reasonable set of unit tests, with output, to main.cpp." I would think with "add a reasonable..." output includes using output types of .h like stdio and/or iostream files. You wouldn't be modifying stack.h and so still following the instructions.
Unless you got additional instructions I am unaware of? Let me know your thoughts and maybe we can learn from this (had me stumped for a while too and maybe this isn't the best explanation).
Thanks,
Rob.
Last edit: Rob Milliken 2020-09-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am wondering if you overthought this. Looking at the file it doesn't say
that you can't include other include files such as <iostream> where you
could easily output your list from your main.cpp file. See: ."...then add a
reasonable set of unit tests, with output, to main.cpp." I would think with
"add a reasonable..." output includes using output types of .h like stdio
and/or iostream files. You wouldn't be modifying stack.h and so still
following the instructions.</iostream>
Unless you got additional instructions I am unaware of? Let me know your
thoughts and maybe we can learn from this (had me stumped for a while too
and maybe this isn't the best explanation).
I recently lost out on a great job because I couldn't pass the coding challenge. I was given a header file that I COULD NOT modify, and asked to fill it out with a stack with a linked list backbone. The problem was to reverse stack data (integers) such that nodes 1..4 contained 1, 2, 3, 4, and the output would be 4, 3, 2, 1. I easily wrote this, with one problem: none of the methods in the class signatures contained any output method other than top(), which returned the top node. Everything else was a void method. So I modified the size() method t]such that it output the values of each node.
I believe this is where I failed. The code contained a "node" method with a data member and a pointer to the next node. The stack class had a pop method, a push method, that size method, top, and that's about it. Both were templates. Other than adding a friend class or resorting to dirty pointer tricks, I could not figure out how to display the data members of the node class.
I really don't understand how this is a valid problem to pose.
Header with comments attached.
Hi TIm.
I am wondering if you overthought this. Looking at the file it doesn't say that you can't include other include files such as iostream where you could easily output your list from your main.cpp file. See: ."...then add a reasonable set of unit tests, with output, to main.cpp." I would think with "add a reasonable..." output includes using output types of .h like stdio and/or iostream files. You wouldn't be modifying stack.h and so still following the instructions.
Unless you got additional instructions I am unaware of? Let me know your thoughts and maybe we can learn from this (had me stumped for a while too and maybe this isn't the best explanation).
Thanks,
Rob.
Last edit: Rob Milliken 2020-09-04
Hi Rob,Thanks for the note. Yes, I figured it out.
On Thu, Sep 3, 2020 at 10:30 PM Rob Milliken robmilliken@users.sourceforge.net wrote:
Good to hear! 👍