Although now the question may be simplified as no brackets, no sin and cos function, and no chain rule. I still want to submit the original version, because the idea in the original quesiton is interesting. Because we need to deal the outside-to-inside chain rule process, we use double Pointers.Then the stack is used to determine the parentheses and go over the term with the fast and slow hands