Programmer account notes (19)

xiaoxiao2021-03-06  82

What should you have to be busy today? I think everyone should not. Because this is the most exciting time when I was young, because I and my brothers were busy preparing that night, I got some stones on the street, line, wooden stick. What is the use? Of course, it is used to play ghosts! (We are too bold!?) It's so brave at the time. But the same today (what? I really don't know what day today? That is July 14 ghost festival!), I have a friend to play again, but the one has been 18 this year, Growing up, certainly can't be less than a child. So we didn't take anything, just took the most important thing, of course, money, "rich to make the ghosts". However, we still drink some things soon, I will go home soon, there is no thing on the road to follow me.

That is, because this time I have to write tonight is also mistaken, I have to pay it back today (No. 23). In fact, from the day before yesterday, it is already the test of the test of the programmer. I hope everyone can do it yourself when I speak. Below we have begun to write the test questions for this 2001-year program exam, as follows:

Read the following programs and C code, write the words of __ (n) __written in the corresponding column of the answer sheet.

[Program Description]

The function of the function first_insert () in this program is to insert a specified value of the design, the function REVERSE_COPY () function is copied by a new list, but the table of new list tables is copied in the list of known chains. The order of the meta link is reversed in the order of the sequence of the known chain table; the function print_link () is used to output the value of each table element in the linked list; the function free_link () is used to release the full table element space of the linked list.

[Program 2]

#include

#include

Typedef struct node

{

Int Val;

Struct Node * Next;

} Node;

void first_insert (node ​​** p, int V)

{

Node * q = (node ​​*) Malloc (sizeof (node));

Q -> va1 = v; __ (1) __; * p = __ (2) __;

}

Node * reverse_copy (Node * P)

{

Node * u;

FOR (u = null; p; ​​p = p -> next) first_insert (__ (3) __);

Return U;

}

Void Print_LINK (Node * P)

{

For (; __ (4) __) Printf ("% D / T", P -> VAL);

Printf ("/ n");

}

Void free_link (node ​​* p)

{

Node * u;

While (p! = null) {u = p-> next; free (p); __ (5) __;}

}

void main ()

{

Node * LINK1, * LINK2;

INT I; linkl = null;

For (i = 1; i <= 10; i )

First INSERT (& Link1, i);

LINK2 = Revere_ Copy (LINK1);

Print_link (link1); FreeJink (Linkl);

Print_link (link2); Free_LINK (LINK2);

}

This is the problem of the list. In fact, we know that there will be a topic of the list every day, so everyone should be ready to take these 15 points. I have said before the linked list, and I will not go any more here. Everyone will do these fill in these fills, we have analyzed the discussion. Void first_insert (node ​​** p, int v) {node * q = (node ​​*) malloc (sizeof (node)); q -> va1 = v; __ (1) __; * p = __ (2) __; } This function is equal to establishing a linked list, but the most specialty here is to use a pointer to the pointer. In fact, there is no big deal, because the pointer is also a variable, of course, there is a address! Then we just define another pointer to point this pointer. Using the factor of the pointer is because this function does not return a value, we want to return to the address to call there, you have to use the address to pass. Take a look at the first empty, the function of the whole function is to insert a new knot in the chain head, then fill in this empty, it is of course good, it is Q-> next = * p, why P is address and * ? The above is not an explanation of this pointer to the pointer. Of course, it is to obtain the chain head pointer, and put the new node on the header of the list. The second empty is also too simple, because we have to refer to the chain header, so turn the new joined node into the head node, that is, the Q is the line.

Node * reverse_copy (node ​​* p) {node * u; for (u = null; p; ​​p = p -> next) first_insert (__ (3) __); return u;} This empty is the same, copy a new one Anti-sequence chain table. Because the first_insert () parameter is in the form of a pointer, we have to use & take the address to assign a function in the function. There is also another parameter to data, data is the data of the P pointer just in the loop. Now you can fill this empty, P-> Val, this is done.

Void Print_Link (Node * P) {for (; __ (4) __) Printf ("% D / T", P -> VAL); Printf ("/ n");} If you calculate a linked list, this output is not I have nothing to say, the answer is P; p = p-> next.

Void free_link (node ​​* p) {node * u; while (p! = null) {u = p-> next; free (p); __ (5) __;}}

This is also relatively simple, it is easy to see, because the linked list cannot be disconnected, so delete is also one of the order, not, you can delete it. Be sure to have a temporary variable to save the integrity of the linked list to completely delete the linked list, the answer is very simple p = u. Although it is difficult to say, friends who don't understand the list will have to take some opportunities. If you have any questions, you can send E-mail, e-mail is zhgpa@sohu.com, but you are also an initiator, willing to make progress together with you.

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

New Post(0)