Browsing the archives for the stack tag

Queue Using Stacks

Tweet Question: How would you use stacks to implement a queue? Answer: So how could we go about doing this? What if we used two stacks and used one as the incoming stack and the other as the outgoing stack? A queue is a FIFO structure, so when we enqueue something, we need to make […]


Reverse a String

Tweet Question: Reverse a string in C using as little additional memory as possible. Answer: The first solution needs the┬ásize of a char and size of two integers, all of which will be allocated from the stack. This solution is the most commonly accepted “good” solution. Here is the code. void reverseString(char* str) { int […]