当前位置:网站首页>About one-way linked list
About one-way linked list
2022-06-10 11:15:00 【Learn Niuniu】
1、 Single chain list
Single - linked list is a chain - access data structure , A set of storage units with arbitrary addresses are used to store the data elements in the linear table . The data in a linked list is represented by nodes , The composition of each node : Elements ( The image of the data element )+ The pointer ( Indicates where subsequent elements are stored ), An element is a data unit that stores data , A pointer is the address data that connects each node .
2、 Data structure of single linked list

head Is the head node , Don't store any data , Its function is to point to the first node in the linked list that actually stores data
among DATA For data fields , This memory stores data ;NEXT It's an address field , The data type is pointer , This memory stores the memory address of the next memory segment .

3、 Headlined list
A linked list with a header means that there is a header node when the list is initialized , And the header pointer always points to the header node , There is no data in the data field of this header node . As shown in the figure

4、 Circular linked list
Circular linked list refers to the end node pointer of the linked list pointing to the head node address , So as to form a ring, as shown in the figure :

Source code is as follows :
#include <stdio.h>
struct link // Structure
{
int data; // Data fields
struct link *next; // Pointer to the domain
};
int main()
{
struct link n0, n1, n2;
n0.data = 10;
n1.data = 20;
n2.data = 30;
n0.next = &n1;
n1.next = &n2;
n2.next = NULL;
printf("%d\n", n0.data);
printf("%d\n", n0.p->data);
printf("%d\n", n1.p->data);
return 0;
}5、*“.” and “->” The difference between
C In language “.” What you give is an immediate address ,“->” A pointer is given ."." The left operand of is a value ,"->" The left operand of is a pointer ."." and "->" In fact, it can be merged into one operator , In many new languages, the members of values and pointers have been unified as "." 了 ,C It is only a continuation of tradition .
6、* Structure
The structure is in C Language belongs to the custom data type , We know that an array is a collection of the same data type , That structure can be seen as a collection of different data types , For example, we need to store the name of a game character 、 Grade 、 Blood volume value 、 Defense value 、 occupation 、 Skill level information , We will find that these attributes correspond to different data types , In this case , In order to better correspond to the role , We can encapsulate all their relevant information into one type , At this point, we will use the structure to perform the consent encapsulation , So the structure is also C A very common data type in language programming
Traverse 、 Head insertion 、 Tail inserted linked list
#include <stdio.h>
#include <stdlib.h>
struct links
{
int data;
struct links *next;
};
void showList(struct links *p)// List traversal
{
while(p)
{
printf("%d\n", p->data);
p = p->next;
}
}
void installTail(struct links **h, struct links *n)// The tail interpolation
{
n->next = *h;
*h = n;
}
struct links *headInsert(struct links *h, struct links *n)// The first interpolation
{
n->next = h;
return n;
}
int main()
{
struct links *head = NULL;
struct links *h1 = NULL;
int i = 0;
int data[10] = {1,2,3,4,5,6,7,8,9,10};
while (i < (sizeof(data) / sizeof(int)))
{
h1 = malloc(sizeof(struct links));
h1->data = data[i];
h1->next = NULL;
installTail(&head,h1);
//head = headInsert(head,h1);
i++;
}
showList(head);
return 0;
}*malloc Dynamic memory allocation , It is used to apply for a continuous memory block area of specified size to void* Type returns the address of the allocated memory area , When you can't know the exact location of memory , Want to bind real memory space , We need to use dynamic memory allocation , And the allocated size is the size required by the program .
At last, a poem by Mr. Qiu Jin is attached for your appreciation
sacred · Live in Beijing
Live in Beijing , It's the Mid Autumn Festival again . For the yellow flowers under the fence , Autumn looks like wiping .
Songs on all sides end up breaking Chu , Eight years of flavor, Tusi Zhejiang .
I will send Nong Qiang as a moth eyebrow , I don't care !
No body , Male column . The heart is better than , Man lie !
All my life , Because people are often hot . Who knows me ? The end of a hero is a struggle .
Where can I find a bosom friend ? Green shirt wet !
边栏推荐
猜你喜欢

Carbon reduction in the construction industry is by no means a fresh idea experts suggest strengthening the transformation of rural buildings

软件测试质量与保证大题

数商云家具行业供应商评估管理系统:提升家具企业核心竞争力,实现数字化协同管理

Sword finger position operation

Software testing quality and assurance

Flink CDC + Hudi 海量数据入湖在顺丰的实践

Analysis: a stable currency is not a "stable currency", but a product in essence
![[WIP] Openstack Masakari (by quqi99)](/img/ea/c0a1c80251a76a6bb7fa0f58424591.png)
[WIP] Openstack Masakari (by quqi99)

MySQL数据类型

87.(leaflet之家)leaflet军事标绘-直线箭头修改
随机推荐
【管理知多少】独立冲突之外,你做不到
C 12 circular queue
核酸检测机器人
【黄啊码】老师,高考后我想选软件开发相关专业,你觉得选哪个方向好?高考志愿怎么填报?
使用matlab生成正弦波、三角波、方波的COE文件
微信小程序注册流程详解
PV operation daily question - orange apple question (advanced version)
2022年Z-Wave生态系统状态报告
【BUUCTF】[Zer0pts2020]Can you guess it?
Transfer of 30% equity of Zhuhai Gaoyuan Electric Energy Technology Co., Ltd., shared by tamigou
【黄啊码】如何确保php上传的图片是安全的?
PV operation daily question - orange apple question (advanced version)
On line monitoring of oil content in compressed air of power plant with PID photo ionization detector
Day 2 linked list (simple)
Review the growth evaluation of central enterprises and listed companies
ModStartCMS 企业内容建站系统(支持 Laravel9)v4.1.0
What about the interface that needs to be logged in first when using the apipost test interface (based on cookies)?
【黄啊码】SVN版本控制教程
杰理之获取 BLE 广播包、profile 数据的接口【篇】
fragment实现底部导航栏不刷新切换