Stacks and queues are very important two data structures, stacks and queues are also linear structures, and linear tables, stacks, and queues are the same logical relationships for data elements and elements of the three structure
The difference is that the operation of the linear table is unrestricted, the stack and queue operations are limited (following certain principles), so stacks and queues are also known as constrained linear tables.
Stack definition: Operate a linear table at the end of the table, top of stack: Top, bottom: Bottom. No data in stack: empty stack
Representation method: S= (a1,a2,a3,a4........an) A1 is the element at the bottom of the stack, an element at the top of the stack. The n data is inserted into the stack sequentially, and the data in the stack is reversed.
The principle of adherence (last on first out is LIFO) or (first in last Out is FILO)
There are many other things in real life: washing dishes, using plates
c#2.0 The following versions only provide a non-generic Stack class that inherits the ICollection, IEnumerable, and ICloneable interfaces. C#2.0 provides a generic type of
The Stack<t> class, which inherits the Ienumerable<t>, ICollection, and IEnumerable interfaces.
Storage and implementation of stacks
1. Sequential stack: a contiguous storage of space to store elements in the stack, continuous space is the array representation.
2. Chain stack: On the basis of the linear list of operations, it is said that the storage structure using the form of a list of the operation is the Filo way.
Examples of life
Is there any other way to use it besides washing dishes?
1. Numeric conversions are conversions of non-negative numbers into other decimal numbers, and the general solution is the Euclidean method, for example: decimal 5142 rpm
into octal:
There is a figure we can see (5142) 10 = (12026) 8
Conversion ideas:
1. Determine that N is not 0 n%8 pressed into the stack
2. Determine that N is not 0 n%8 pressed into the stack
The last n is 0 stops, so that the data in the stack is all one of the POPs to get octal values.
2. Common problems in programming: bracket matching, simplification, only two parentheses match: () and [] nested order is arbitrary
([] ()) match [() [()] []] match [(]) mismatch, add a bunch of such matching symbols how to judge?
Thought: 1. If the stack is empty, the push
2. If the brackets match the brackets at the top of the stack, the parentheses at the top of the stack pop
3. If the brackets do not match the brackets at the top of the stack, the brackets push
4. At the end of the last time to determine whether the stack is empty, is empty and matches, not empty, does not match
3. Commonly used arithmetic expressions ... you can think for yourself ...
Not to be continued ...
C # data structure stack stack