replace the stack with c++ stack structure