Data Structure--tree (medium)--The problem of linear structure

Source: Internet
Author: User

The problem of linear structure explains "example" reversal chain list

Pack This system is a black-box test, no matter what your code looks like, as long as the results are right. Java

Are linked lists useful only in C and C + +? Because there is no pointer in Java. An array of structures is also possible.

What is an abstract linked list?

The list needs to have a block of local data, there is a block of places to save the pointer-the address of the next node.

Single-linked list reversal

    • Can add a head knot (personal habits?). )
    • New refers to the position of the head node of the newly reversed good list.

    • Old refers to the position of the head node of an older linked list that has not yet completed a reversal

    • TMP refers to the node to be saved to prevent losing

Reverse reversal, starting from 1, 2 to reverse, but to remove 2 points to 3 points and 2 points to 1, 3 nodes will be lost, the back of the list is all lost, so, first to save 3.

Standard template pseudo-code for single-linked list reversal

PTR Reverse (PTR head,intK) {    intCNT =1; New= head->Next; old=New-Next;  while(CNT <K) {tmp= old->Next; old-Next =New; New=Old ; old=tmp; CNT++; } head->next->next =Old ; return New;}

This is the standard template for single-linked list reversal, but pack is a black-box test,

You can also use stacks,

Test data

There is no tail reversal

Address fetch upper and lower bounds

Just full reversal.

K=n full Inversion

K=1 No reversal

There are extra knots.

Max, Min

Boundary test.

Data Structure--tree (medium)--The problem of linear structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.