Programmer accounting note (21)

xiaoxiao2021-03-06  103

Soon today is the days of the end of the course, and now the mood is really difficult. So I also said less, because I can't use the text to express my present mood. Before school, the teacher also agreed to us, if we got a programmer, please ask us to eat. I must work hard to get the meal, everyone works hard, I am grateful when I see it. Ok, let's talk about the last day. Today, it is still around the exercises, and is the topic of the list (I emphasized again, the chain list is the focus of the exam). See the program: Typef struct elem {int val; struct elem * next;} intNode; / * Definition This structure knows that it is a list * / / * merge ascending chain table * / intNode * Merge (intNode * a, intNode * b) {intNode * h = a, * p, * q; while (b) {for (p = h; p && p-> val val; q = p, p = p-> Next) ; / * Note that the double pointer * / if (p = = H) ____ 1 ____; ELSE_____2____; q = b; b = b-> next; ____ 3_____;} return h;} Look, know this is two linked list Synthetic a new list, the parameter is of course there is two linked lists. This procedure is also relatively simple, just testing our familiarity, I have talked a lot of knowledge about the list of linked lists in the posting note in the previous few days, so I will not go. Let's take a look at how to fill these empty IF (p = h) _________; Else_____2____; here is the reason if it is inserted in front of the head knot, which is of course the characteristic of the one-way linked list. From the conditions in the context P-> Val VAL know that when B-> Val is less than P-> Val, we have to plug, of course, the point to point B. The first empty can write h = b immediately, and now it is not to insert the head knot. This problem is relatively simple, here uses two pointers, ie Q and P, q must be a node before P, why do you want to use double pointer? This is also the shortcomings of one-way linked list. The second air filling Q-> Next = B, the following Q = B is the node before P, b = b-> Next continues to prepare the next node to be inserted, the third space can be pressed The form of the list can be fill what to fill it. In fact, didn't point B-> next to its next node, but we have moved B = B-> next to the next node, so I can't use B. -> Next = P, but the good Q is to assign B's address to it before, the third empty is of course Q-> next = P. Below we tried to change this program, in the above program, the two linked lists are already the characteristics of the sequence, so the efficiency is not high.

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

New Post(0)