Use the methods for stacks and queues developed in the course to write the following function: "Empty one Stack onto the top of another Stack in such a way that the entries that were in the first Stack keep the same relative order". In writing your function, be sure to check for empty and full structures as appropriate. Your function may declare other, local structures as needed.
Difficulty level
This exercise is mostly suitable for students
void stacks(Stack *s1, Stack s2)
{
element e;
while(Top(s2,&e))
{
Pop(&s2);
Push(s1,e);
}
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Convert an integer to words