Hello, the below code for the Towers of Hanoi problem was taken from class notes
ID: 3621099 • Letter: H
Question
Hello, the below code for the Towers of Hanoi problem was taken from class notes. We were given the recursive and non-recursive solutions to the problem along with a solution that uses stacks.For the stacks solution, I tried copying the code from various slides and then running it, but I had a few problems.
-> My compiler (DEV-C++) doesn't recognize "return TRUE" or "return FALSE". I'm not sure what to replace the TRUE and FALSE with..
Here is the code (it may be missing parts for all I know, but this is all that was in the notes):
#include<stdio.h>
#include<stdlib.h>
#define DEFAULT_SIZE 7
struct stack{
int top;
int elements[DEFAULT_SIZE];
};
typedef struct stack stack;
//Function prototypes
stack init_stack(stack s, char *name);
int push(stack *s,unsigned int i);
int pop(stack *s);
int isempty(stack s);
int isfull(stack s);
//Main function*************************************************************************
void
towersOfHanoi(int n, stack *src, stack *aux, stack *dst) {
if( n > 0 ) {
towersOfHanoi(n-1,src,dst,aux);
push(dst, pop(src));
print_state();
towersOfHanoi(n-1,aux,src,dst);
}
}
//Functions******************************************************************************
stack
init_stack(stack s, char *name) {
s.top = 0;
return s;
}
void
dispose(stack s){
free(&s.elements);
free(&s);
}
int
push(stack *s, unsigned int i) {
if(isfull(*s)){
printf("Warning: Push on full stack ");
return FALSE;
}
s->elements[s->top] = i;
s->top++;
return TRUE;
}
unsigned int
pop(stack *s) {
if(isempty(*s))
printf("Warning: Pop from empty stack ");
s->top--;
return s->elements[s->top];
int
isempty(stack s){
if(s.top == 0)
return TRUE;
else
return FALSE;
}
int
isfull(stack s){
if(s.top < DEFAULT_SIZE - 1){
return FALSE;
}
else
return TRUE;
I would appreciate any help with editing the code so that it runs.
Thanks