Data structure Practice project--stack

Source: Internet
Author: User

This group of projects addresses 1-6 lessons in the basic series of data Structures (3): Linear table:
1 "Stacks and queues" guided learning
2 Definition of stacks
Sequential storage structure of 3 stacks and its basic operation implementation
4-stack chain storage structure and its basic operation implementation
Application of 5 stacks 1-expression evaluation
Application of 6 stacks 2-maze problem

"Project 1-build the sequential stack algorithm library"
Define the sequential stack storage structure, implement its basic operations, and complete the test.
Requirements:
1. The header file Sqstack.h defines the data structure and declares the function used to complete the basic operation. Functions that correspond to basic operations include:

void  initstack (SqStack *&s    ); //initialization stack  void   Destroystack (Sqstack *&s); //destroy Stack  bool      Stackempty (Sqstack *s); //stack is empty  int   Stacklength (Sqstack *s); //returns the number of elements in the stack--stack length  bool  Push (Sqstack *&s,elemtype e); //into the stack  bool  Pop (Sqstack *&s,elemtype &e); //out of the stack  bool  GetTop (Sqstack *s,elemtype &e); //fetch the top data element of the stack  void   Dispstack (Sqstack *s); //output stack   

2. Implement these functions in Sqstack.cpp
3. Complete the test in the main function, including the following:
(1) Initialize stack s
(2) Determine if the s stack is empty
(3) in turn, the stack element a,b,c,d,e
(4) Determine if the s stack is empty
(5) Output stack length
(6) Output from stack top to stack bottom element
(7) Stack out and output the stack sequence
(8) Determine if the s stack is empty
(9) Release stack
[Reference Solution]

"Project 2-Build a chain stack algorithm library"
Define the chain stack storage structure, implement its basic operations, and complete the test.
The specific requirements refer to item 1.
[Reference Solution]

"Item 3-matching of parentheses"
Suppose that three kinds of parentheses are allowed in an expression: parentheses, brackets, and curly braces. Write an algorithm that determines whether the various opening parentheses in an expression match the closing parenthesis.
For example, input (3+4)[2+{[3]}-8, the output matches correctly, input the 3+4[2] +{[3]}-8, output matching error.

Hint: (1) encountered the left parenthesis into the stack, after encountering the right parenthesis, a symbol to see whether pairing. If paired, continue until all the symbols are read, and the stack is just empty. If there is a mismatch in the middle, or ____, you can draw a conclusion that is not paired. (2) You can also design a function that returns a Boolean, the argument is the expression to be paired, and is a string.

[Reference Solution]

"Item 4-Numbering conversion"
Converts a decimal integer to any of the binary outputs between two and nine. Please use the stack design algorithm and implement the program.
Tip: To convert to R, the original number is divided by the cardinality R (after the end of the business), until the quotient is 0, the inverse of a series of remainder is the conversion result. The "reverse order" here means that the remainder will be output first, LIFO, and the stack of opportunities ...
[Reference Solution]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Data structure Practice project--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.