hello .. how can i write a function that convert a decimal number to binary in a stack?
i need a simple implementation
1)read the number
2) loop fpr checking if the number >0
3)print it
pop and push are allowed
thanks alot
hello .. how can i write a function that convert a decimal number to binary in a stack?
i need a simple implementation
1)read the number
2) loop fpr checking if the number >0
3)print it
pop and push are allowed
thanks alot
Do you know how to do this without a stack?
Assuming you do, having extracted a single bit, the only thing you can do with an otherwise empty stack is push()
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
can you help me with a code "with stack" please?
assume that my function prototype is
void convert()
Are you using std::stack<int> as your stack, or do you have to write your own.
> can you help me with a code "with stack" please?
Since the interesting part is only two lines in a loop, not yet (not at least until you've shown a bit of effort). Posting something which doesn't work (and I don't mean posting any old rubbish either).
If you know how to do it normally, then think about the "it comes out backwards" problem, which is where the stack comes in (google LIFO)
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Understand what >> and & operators do. Then you'll be pretty much finished with the problem.