Two articles introduced two linear storage structures, arrays, and linked lists. They have their own advantages and disadvantages, so that you have to use them. If you use it, you will help you.
The care and lift of the friends, many pairs of two articles have been commented. Many people feel that it is too long and is too lazy to look. I don't think that the empty things and theories have written enough in the textbook, and you need to write some practical things. When schools, many times are that books don't know how to start. In fact, this time maybe theoretical knowledge is very familiar, and it is probably no problem. If you don't have to write code demonstration, you can go to the second grade learning, the school girl lecture class (exaggerated). At that time, I wanted to find a write code, but the conditions were not allowed. Now work, I feel that some simple things will be seen to see if I still have any problems. Maybe it's not perfect, there will be a lot of vulnerabilities, but I think it can still play the effect of "understanding the spirit". The code is much more, because the package is more than the method, but also uses some unused things, which is also an improvement in breadth.
I wrote these code, debug passes on VC6.0, where I also make a single step debugger. You can copy these code and add #include
Write the topic after doing some replies for the stickers. This article introduces a stack.
In the textbook, the stack is like a gun shuttle, and the last bullet will go out first. This is already very image, it is also very understandable. It is said that the stack is the container that is only added and deleted only on the top of the stack. Therefore, the stack is a "secondary first out" (LIFO) data structure. So, what are the functions of the stack?聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽 聽聽I went back and returned to the work that I just interrupted. " As can be seen from this example, the stack energy records have been partially completed.
Say the basic concept, this is very understandable. I think it is more conducive to understanding. For example, when a method is called in the program, the address of the first instruction after the instruction is called into the top of the stack in the method of the current thread. When the return command of the called method is performed, the address is popped up from the stack and then proceeding from the address.
The simplest data structure in many containers is the stack. It only provides PUSH and POP operations. The former is pressed, the latter is popped up. In addition to both operations, typical stack operations also provide a TOP operation. It always returns the data item on the top of the stack without deleting it.
First, create a base class for stack. This class defines three pure virtual functions of PUSH, POP, and TOP. This polymorphic method can be used to implement the stack of this data structure in our approximate group and linked list.
Template
The way to implement Stack with a chain is as follows:
Template
Template