Wild front-end data structure exercises (1)--Stack

Source: Internet
Author: User

The exercises are mainly selected from the book "Data structure and algorithm JavaScript description" published by Orelly.

Reference code visible: Https://github.com/dashnowords/blogs/tree/master/Structure/Stack

Basic Exercises
    1. Implement a class based on the characteristics of the stack Stack , and use it in subsequent topics when you need a stack.
    2. Write a function unitTrans(num, unit) , num for a 10 decimal number, unit to convert the number of binary, to seek the results of the conversion.
    3. Write a function recursion(num) num for a 10 binary number that requires num! the output result.
    4. Writes a function palindrome(str) that str is a string, if it is a palindrome string, then returns true , otherwise returns false .
After-school exercises (fourth in the book)
    1. In an arithmetic expression, there {} are () [] three kinds of parentheses, write a function, accept an arithmetic expression as an argument, return if the parentheses match exactly true , or return the position where the parentheses are missing.
    2. The suffix expression for an expression is opt1 opt2 operator, which writes a function that accepts an arithmetic expression as an argument (an infix expression in the form of an arithmetic expression that is usually used) and converts it to a suffix expression (which can be persisted regardless of the priority of the operation).
    3. In the box from top to bottom there are an indefinite number of "red", "white", "xxx" three kinds of sweets, write a program, you can use one or more stacks, in order to ensure the original candy sequence unchanged, remove all the "xxx" candy.
Exercise Ideas
    1. The expression is parsed by character, and the opening parenthesis is pressed into the stack, and the closing parenthesis pops an element from the top of the stack to see if they match, and if the match continues, the position is returned if the mismatch is not matched. It is important to note that the final state of the stack needs to be empty if all brackets are fitted.
    2. Reverse parse the original expression, will 操作数 and 操作符 respectively press into two stacks, and then first popped from the operand stack first element, in turn from the operand stack and operation Ching popup elements until the stack is empty. If the front-to-back parsing, the top of the stack is the last element, the stack is taken into account in order.
    3. Only with an extra stack, the "Red" "white" candy pressed into the new stack, the xxx candy removed, when the candy box is empty, and then the new candy stack one by one pop-up elements back to the candy box stack.

Wild front-end data structure exercises (1)--Stack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.