Programming, this is the case - how to learn program design

xiaoxiao2021-03-06  23

There are many netizens who have confused: "How can I learn the programming?", This is not one or two words can be said clearly, so I wrote this article, giving the majority of enthusiasts a way to solve No matter what kind of "bird" you believe that you can find what you want in this article is that the program is designed from a famous formula: program design = data structure algorithm whenever I write this At the time of the formula, there is always a new feeling in my heart, but it is difficult to fill a major appraisal and Bill · Gates, which is a good friend, and I have anatomized this formula for everyone: "program design" To put it bluntly, everyone is so-called programming, no matter what profound connotation in this word, first look at the two nouns on the right side of the equation. According to the official definition: the data structure is the operational object of the computer in the programming problem of non-numerical calculation, and the relationship between the relationships and operations thereof; the algorithm is a description of the specific problem solving step, which is an orderly sequence of the instruction. The official explanation is a classic, but we have seen it more confused. Don't worry, listen to me to explain it. The program is like covering the house, the data structure is like bricks, watts, and the algorithm is design drawings. If you want to cover the house, you must first have a raw material (data structure), but these feedstocks cannot automatically cover the house you want; you must follow the description of the design drawings (algorithm). This way you can have the house you want. The program is also the same, and you have various functional statements or basic structures (such as read / write / real / bolean et al.). They don't automatically arrange them. The program code. You have to write according to the function specified in the process, and the functionality of the program is that the embodiment is the specific embodiment of the algorithm. So, it is popular: You must arrange a specific functional statement and the basic structure according to a specific order, form a program with a specific function, this is: program design = data structure algorithm. The data structure is the foundation of the program design, no foundation, no matter how high the design is, this building cannot be built. The algorithm is the idea of ​​programming, its soul! Procedures with no souls can't be called, just a pile of messy symbols. In programming, the data structure is like substances, algorithms are conscious. This is like philosophical: consciousness is dependent and substance, the substance is due to consciousness. Both sides are interdependent, it is not possible! The content of data structure does not only have several basic structures that come with the basic structure (like sequential structure, branch structure, cyclic structure, function procedure) data type (integer, real, Boole, character, etc.) and user-defined high-level points. Data structure (array, collection, file, pointer (queue, stack, tree, diagram, etc.) ······) is so much. But the algorithm is different, it is more and more! It allows you to let the data are arranged in the way you want (of course, you need to comply with grammar and functional requirements ^ _ ^). Based on the side, the data structure is the various organizations, organs and algorithms of the human body. You can use your thoughts to dominate the individuals of your body.

If you want to take an apple, you can go through, you can run past, as long as you think, you can even climb the past. But in any case, your organ is still your organ (not changed), the purpose is the same purpose (apple), but the way is what you want! This is the flexibility of the algorithm, not fixed. So you can say this: The data structure is dead, and the algorithm is live! I understand a lot now! How to learn how many data structures have been described above in the programming design, so efforts to learn a good data structure is the first step in learning programming and a key step. You will feel difficult, boring (in fact, I am thinking about it at the time, what standard file, standard type, standard function, and standard process don't worry. So, many beginners are tired of, stagnating, retreating. If you want to make a good program, you think: Is it difficult to fill me like this little? What else should I challenge Bill · Gates? I will be able to do it, believe in myself, I will have to pass this. In this way, you have the most basic quality of programmers - perseverance. This is the necessary thing, otherwise you will not stop in the long time of the development program. And only this can calm down and learn. There is no shortcut this time, only read more books, practice more, and find all the structures and types of usage. If you don't understand, you can ask, you can go to the 9CBS technology community. Best, there is a teacher guidelines, which is much better than yourself in this way, and often more than half of it. Remember! Just cross the first step, it will be too much in the future, everything is difficult! Be sure to stick to it. After you have passed this time, you find that the program design doesn't have the same thing as you think. When you learn all Dongdong, the gate of the program design has opened a fan, and the other is ... ····· Algorithm, this is the focus of programming, it is also difficult. The difference between many rookies and old birds is mainly the proficiency of the algorithm. There are many friends who have asked me like this: "I have learned above my data structure, and I know how to use it, but why do I still programmed? In fact, this is a specific thing that lacks algorithm ideas. Performance. It is not to learn the data structure will be programmed. The algorithm is flexible, it does not have a fixed form as the data structure. The algorithm is not fixed to determine its characteristics, you can't put all the algorithms I have learned, because it is endless. But if you can put the limited algorithm of yourself, you can't afford it. Just like you only learn 1, 2, 3, but you can Composition 12, 23, 32, 123 ·····. So this way is long, there is a shortness of the difficulty. There are many ways to learn good algorithms. I will give you a few examples here. First You have to develop a good programming style and habit. This is also a lot of species. The most important thing is to develop the procedures and methods of gradually refinement from the top, how can they gradually ask themselves? The fine program is designed. For example, there is such a problem: the two sides and angles of the triangle are known, and the third side and the area are obtained.

Now, when you see this question, you don't immediately go to write, but think about how to solve (algorithm), then write her down to avoid forgetting. So I wrote: 1 level algorithm: 1 Enter the length A, B, and angle A 2 calculate the third sides C and the area S 3 output C and S after you write, you feel that the second step is not very clear , You can't write code, then continue to seek fine. Secondary refinement: 2-1, convert the angle of α into radians; 2-2, c = SQRT (A * a b * b-2 * a * b * cos (α)); 2-3, s = 1/2 * (A * b * sin (α)) Haha, is this problem not to be solved? Then you can easily compile. Take a closer look at the steps: first write a first-level algorithm, if you think there is something you can't get the source code, or have a lot of steps to write, then continue to seek, until you think it can be very clear Write code. But seeking from people can vary from person to person, like the topic above, if a prawn compared with many programs, may not have to write it directly, the code can be written directly; but if a rookie (like me) May be written to secondary refinement. In this way, you may think that this refinement is too slow, or it is a waste of time. I tell you loudly: it is not! This is a numerous programming pioneer, programming the basic method recommended by people. Do you know where to program, where is the main time? Not writing code, but used in solving algorithms and debugging procedures! The essence of algorithm is the best way to shorten these times. It allows you to construct algorithms without having to construct algorithms, make this process more enormous, more concise; it is also likely to make you a long time for a small bug, because it gives the algorithm already Trend is perfect. In fact, a small outline (algorithm) can solve a lot of problems, is it not the same? ! Therefore, first, seeking the most important habit of seeking the essence algorithm must be developed! There is also a good habit to do: the clarity and readability of the program source code must be high. Why is this? In the source code, the space in front of each line code does not affect the operation of the program, but it affects people's reading. You think, when you see a code, the format is messy, there is no headache inside and outside, and it is definitely the first time I don't want to see it next. And when you debug such a code, you will not find the north by a small error. If the format is very clear, such code is very easy to read, the structure is very clear, and Begin..nd looks clear. I think this code is read and debugged. There is also an annotation after some important code blocks, or improve program readability. If you don't say others, I have a deep understanding: I used to have a notes, I was very clear about it, but after a few weeks, I saw that the code was like looking at another person. Less workers can figure out that the more the code is. It's hard to understand your code, not to say others. Therefore, the cost of the fitness is still worth it.

The person who likes to use the goto statement to jump, although the flexibility of writing code is added, but it seriously undermines the structure of the program, it is easy to cause the logical confusion of the program to operate and the brain thinking, it is likely to cause some very easy Founded mistakes. And all GOTOs can be replaced with other statements. So here I suggest that everyone will use GOTO. Can not be used without it. The above is to improve the clarity and readability of the code. The above is used to introduce the role and benefits of good habits in program design. This is a basis for programming, I hope to help everyone. The following describes other methods for promoting programming levels. Second, there are more practice and a lot of experience, research and appreciation of others' excellent program code (the important point of the clarity and readability of the above) is reflected here). Whether you do anything, only frequent exercises can be skilled in order. It can not only help you improve the degree of cognition of the algorithm, but also make you better understand the data structure; and exchange experience and appreciate others' code is to learn others' excellent unique insights and logical thinking, many 'old Bird 'is slowly growing in research outstanding code. But research and appreciation does not mean let you 'all Westernization'; it is not necessary to stick to himself a constant thinking method, don't be a highway of other people's thoughts, but let you take a long time, take it, take it This is what I want to say. In addition, when compiling a program, think more about a few different algorithms, repeated comparison, see which one is more suitable for this program. This way, not only helps to improve your running efficiency, but more importantly, help to improve your breadth and thinking of the algorithm. After doing so much, you will find that the semi-gate of the program is not as easy to open; but if you can take the lonely and boring test, press the class, step by step, think, unconsciously you The level has increased much. In addition to the above-mentioned refinement algorithm and data structure, mathematical methods and logic ideas will have certain impact on your programming (this also algorithm) first talk about mathematics, which is an important assistant that guides you to learn. For example, you have to achieve a seemingly complex function, and you have written a lot of code, what structure and type are used, but it is not real. At this time, don't worry, maybe you have to calm down before you do this function, think carefully, see if there is a special formula for mathematical learning to achieve this problem? If you really feel the big hair, dig it out, congratulations! (Answer!) I think you will be happy in this time, this feeling, I think everyone will definitely experience when doing math or other problems. This is said that the space cave is not as good as an example: 8 'cars' on the 8x8 chess board, if they can't eat each other, then 8 'car' is in a safe state. How many different safety status is there? For such questions, the method is used to use the 'backtracking', that is, the order of fixing a chess piece, then put the remaining progressive test, if you can put one, if you can't change the chess pieces, Until all methods are used (traversal). This seems that this method is really troublesome, and it is not necessary to write a lot of code, but also use 'recursive' (an important algorithm for programming). The efficiency of the program is greatly reduced. But we can think about there is no better mathematical approach. there must be! You can see it in the first line, the chess pieces can be placed casually in 8 spaces and will not be attacked; and the second line, the chess pieces are only available in the seven spaces; the third line is only 6 ... ... Introduce the 8th line, there is only one space left.

转载请注明原文地址:https://www.9cbs.com/read-41292.html

New Post(0)