C/C ++ single-chain table

Source: Internet
Author: User
Tags field table

Let's look at the example. Example 1: Define a linked list.

 stu 
{   int name;
age;
stu *next;
};

  

Store data elements in a linear table in any storage unit with a set of addresses. : Element (Data Element Image) + pointer (indicating the storage location of the successor element) = node (indicating the image of the data element or data element)

I have to say that Baidu is too official.

 

 

1. Meaning: the combination of multiple groups of different types of numbers (array storage is not continuous)

2. Composition: Header + node + Table end

Node = data domain + pointer domain

Header: only the end of the pointer field table: only the data field

In the past, the teacher spoke well and had a profound impact, but it seems that it is still a bit cloudification.

 

Linked List understood by LZ

1. The linked list is a series of struct

2. This struct has a special pointer of the struct type *.

 

In combination with example 1, it is clear, but the premise is that you must structure the object.

 

This is exactly the case. Therefore, the structure must be used before the linked list is learned, and the pointer must be used before the structure is learned. It seems difficult, but not difficult. All complex types are composed of basic types. The same is true for linked lists, but a fashionable name.

Example 2: Create a linked list Function

 stu * creat( stu *head,*pf,*(i=;i<n;i++=( stu *)malloc((,i+,i+,&aa,&->name=->age=(i===head=->next==->next=


In Example 2, we used pointer functions, struct pointers, and pointers, which should not be difficult to understand.

 

From the list creation function, we can see that,

 

Pb = (struct stu *) malloc (sizeof (struct stu ));

This statement dynamically allocates memory space (which was briefly introduced in the previous article ). Each time a node is added, a sizeof (struct stu) space is allocated as needed, and the ideal Communist Party has wood.

Complete example, for example 3:

<Stdlib. h> stu * creat (stu * head, * pf, * (I =; I <n; I ++ = (stu *) malloc (, I +, I +, & aa, &-> name =-> age = (I = head =-> next = print (n, stu * (I =; I <n; I ++, * a, a-> = a-> stu *, & =View Code


Example 3 includes the definition of the linked list, the method for constructing the linked list, and the method for calling the linked list. I can't write a code example 3 at all. I need to know how to define \ structure, how to assign values, how to use them, how to get a specific node, how to assign values to node elements, and how to traverse them, how to Use pointers to access OSS.

 

Related Article

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.