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