C recursive method for inverted linked lists

Updated on technology 2024-03-16
6 answers
  1. Anonymous users2024-02-06

    linklist reserve_fei(linklist l,int n)

    What does n do.

    And this non-recursive inverted algorithm that you think of yourself

  2. Anonymous users2024-02-05

    Inverted linked lists? Dude, what about you going to graduate school, it should be like this:

    The slowest and most 2 is the number length, which is paid to an array, the data is exchanged, and the linked list is recreated.

    The most brain-dead of the general algorithm is to use the stack, first put all the nodes into the stack, and then out of the stack, the first out points to the last out, this change is recursion.

    The general idea is this:

    Linked lists are divided into two types: linked lists with header nodes and linked lists without headless nodes, in any case, the linked list to be transposed is processed into a linked list L1 containing only the leading node of the first node and a linked list L2 containing the remaining nodes of the linked list with a headless node. Then, the nodes on L2 are removed sequentially and inserted between the head node of L1 and its first node, that is, the node taken from L2 is inserted into L1 as the first node.

    typedef char datatype;

    typedef struct nodelistnode;

    typedef listnode * linklist;

    listnode *p;

    linklist head;

    linklist reverselist(linklist head)

    return (head);

    return (head);

    That's probably the case, it's not easy to score points.

    Recursively, it is.

    Linked list transpose function (linked list b).

  3. Anonymous users2024-02-04

    It is the head node (head) that is buckled

    The car is the first node (first son).

    The horse is the secondary node (second son).

    The toothpick is thin with a pointer, the black one is pointing, and the iron head is pointing with a thin head.

    The following is the while loop (condition: the incense head points not to be empty) the first loop brings the horse to the front of the cart, and the second cycle brings the phase to the front of the horse.

    The third cycle brings the taxi to the front of the phase.

    Stop the loop until the incense point is empty.

    **As follows: Only one first node phead is needed to find the linked list and invert it. The details are as follows.

    pxiang = phead->pnext;

    P iron = P incense - > pnext;

    p->pnext=null;

    P incense = P iron.

    While (P incense ! =null)

    P iron = P incense - > pnext;

    p->pnext=phead->pnext;

    phead->pnext=pfragrance;

    P incense = P iron.

    Compared with the pseudo-algorithm (three steps and four cycles), it is a one-to-one correspondence with the ** above:

    Step 1: The incense head points to the first son, and the iron head points to the second son.

    Step 2: Delete the toothpick that points to the second son (the one pointed by the iron head) Step 3: The incense head follows the iron head.

    The following cycle conditions: (Condition: incense head pointing is not empty).

    Cycle 4: The incense head follows the iron head.

    Operate with props a few times, and then memorize the process, and then write ** according to the process in the future.

  4. Anonymous users2024-02-03

    link invert_list(link head)

    return mid;

    Initially.

    mid last

    head->1->2->3->nul

    At the end of the first round.

    mid1head->2->3->nul

    When the second round is in progress.

    last=mid(1)

    1mid=head(2)

    head->2->3->nul

    head->3->nul(3)

    At the end of the second round.

    mid last

    head->3->nul

    And so on eventually.

    head->3->2 ->1->nul

  5. Anonymous users2024-02-02

    The following is a detailed analysis of the example of using recursive and non-recursive methods to reverse a one-way linked list. For example:

    a->b->c->d, which in turn is d->c->b->a. Analysis:

    Suppose the structure of each node is as follows: class node because when inverting the linked list, we need to update the "next" value of each node, but before updating the next value, we need to save the next value, otherwise we can't continue.

    So, we need two pointers to the previous node and the next node, and each time we update the "next" value of the current node, move the two nodes down until we reach the last node.

    **As follows:Copy** **As follows: public node reverse(node current) return previousnode;

    The above ** uses a non-recursive approach, and this problem can also be solved by recursively. **Below:Copy** **As follows:

    The public node reverse(node current) recursion method is actually very clever in that it uses recursion to go to the end of the linked list and then update the next value of each node (penultimate sentence).

  6. Anonymous users2024-02-01

    There are three nodes a->b->c A is the linked list header, and the recursive function is called roughly as follows:

    printlistback4(a)

    Print B, Print A}

Related questions
3 answers2024-03-16

Heada and headb are both singly linked lists with leading nodes. In this algorithm, we delete the common elements from the ith element in the heada linked list, and then insert the single-linked list heada before the jth element of the headb. >>>More

2 answers2024-03-16

Recursion, in a nutshell, is when the application calls itself to query and access hierarchical data structures. The use of recursion can make ** more concise and clear and readable (not necessarily for beginners), but because recursion requires a system stack, the space consumption is much larger than that of non-recursive, and if the recursion depth is too large, the system resources may not be enough. >>>More

5 answers2024-03-16

What exactly is to be done?

9 answers2024-03-16

Scope. You static char *chh;

static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More

11 answers2024-03-16

Valid variable names for the C language:

First, it can only contain numbers, letters, and underscores. >>>More