CS140 -- Final Exam: Question 26 (17 points)


Remember the routines from dllist.h:

typedef void *Dllist;

extern Dllist new_dllist();
extern free_dllist(Dllist);

extern dll_append(Dllist, Jval);
extern dll_prepend(Dllist, Jval);
extern dll_insert_b(Dlnode, Jval);
extern dll_insert_a(Dlnode, Jval);

extern dll_delete_node(Dlnode);
extern int dll_empty(Dllist);
extern Jval dll_val(Dlnode);

extern Dlnode dll_first(Dllist);
extern Dlnode dll_last(Dllist);
extern Dlnode dll_nil(Dllist);
extern Dlnode dll_next(Dlnode);
extern Dlnode dll_prev(Dlnode);


And remember the routines from stack.h (I'm removing the size):

typedef void *Stack;

extern Stack new_stack();
extern free_stack(Stack);

extern int stack_empty(Stack);

extern stack_push(Stack, Jval);
extern Jval stack_pop(Stack);

/* Look at the top element, but don't take it off */

extern Jval stack_top(Stack);


Now, assume that you have dllist.o. In other words, you have doubly-linked lists already implemented. Write stack.c to implement stacks using dllist's. The answer sheet has things started off for you.