One: Stack
Stacks and queues are also linear structures, and the data elements for linear tables, stacks, and queues are the same as those of the data elements of the three structure, and the difference is that the operation of the linear table is unrestricted, and the operations of the stack and queue are limited. the operation of the stack can only be done at one end of the table, and the insertion of the queue is performed at one end of the table while other operations are performed at the other end of the table, so the stack and queue are referred to as the linear table of operation constraints.
1: Stack definition and basic operations
A stack is a linear table of operations that is scoped to the end of the table. The end of the table is inserted, deleted, and so on, so it has a special meaning, the footer is called the top of the stack, the other end is fixed, called the bottom of the stack (Bottom). Empty stack is called when there are no data elements in the stack.
The stack is usually written as: s= (a 1, a 2,..., a n), and S is the 1th letter of the English word stack. A 1 is the stack bottom element, and a n is the top element of the stack. The n data elements in the order of a 1, a 2,..., a n sequentially into the stack, and the order of the stack in reverse, a n the first out of the stack, a 1 the last out of the stack. Therefore, the operation of the stack is based on the principle of last-in, first-out , or LIFO, or advanced-out, or filo , so Stacks are also known as LIFO tables or filo tables.
because the stack can only operate on top of the stack, the stack cannot be inserted or deleted at any one of the stack's elements element. Therefore, the operation of the stack is a subset of the linear table operations . The operation of the stack mainly includes inserting elements at the top of the stack and deleting elements, taking the top elements of the stack and judging if the stack is empty.
The interface definition for the stack is as follows:
1 Public InterfaceIstack<t>2 {3 intGetLength ();//calculate the length of the stack4 BOOLIsEmpty ();//determine if the stack is empty5 voidClear ();//Clear Operation6 voidPush (T item);//in-stack operation7T Pop ();//out of stack operation8T GetTop ();//take the top element of the stack9}
View Code
C # Data Structures-stacks and queues