Data structure of C + + implementation of static linked list

Source: Internet
Author: User
Tags numeric value

First, we let the elements of the array consist of two data fields, and cur. In other words, each subscript of an array corresponds to a data and a cur.

The data field is used to hold the data element, which is usually the data we want to process, while the cursor cur corresponds to the next pointer in the single list, and holds the subscript of the element's successor in the array. We call this list of arrays described as static lists.

The first element of the array, the cur of the element with subscript 0, holds the subscript of the first node of the standby list; The cur of the last element of the array holds the subscript of the first element with a numeric value, which corresponds to the function of the head node of a single linked list, and 0 when the whole list is empty, indicating no point. As shown in Figure 3-12-2

Now if we need to insert a value of "C" between "B" and "Ding", we just need to change the cur of "B" to 7, which means that the next one is "C", and the cur of "C" is changed to 4, which means that the next one is ding.

As shown in Figure 3-12-3.

Now if we delete the first element "a", it means that the position "a" is now empty, if there are new people to come in the future is preferred here, so the deletion of the position becomes the first priority, that is, the first element of the CUR is 1, the first element position of the cur to 8, and the subscript 8 position cur change to 9, The cur of the last element position is changed to 2, as shown in Figure 3-12-4.

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.