当前位置:网站首页>2022.1.23
2022.1.23
2022-06-26 04:38:00 【bu_ xiang_ tutou】
The linear table
1. Zero or more data elements Co., LTD. Sequence .
2. The relationship of each element in the sequence is one-to-one .
3. When passing an argument to a function , Whether this parameter will be changed within the function determines what parameter form to use .
3.1 If it needs to be changed , You need to pass a pointer to this parameter ,
3.2 If it doesn't have to be changed , You can pass this parameter directly .
4. Linear tables have a sequential storage structure ( Array ) And chain storage structure ( Linked list ).
Linked list
Linked list
1. The difference between linked list and array :
The array is convenient for finding data ,O(1), Deleting and adding data is complicated ,O(n);
Linked list lookup data is complex ,O(N), Deleting and adding data is simple ,O(1);
2. A linked list must have a header pointer .
3. A one-way linked list has a data field , A pointer field
struct node{
int data;
struct node *next;
}linklist;
A two-way linked list has a data field , Two pointer fields
struct node{
int data;
struct node *next;
struct node *pre;
}linklist;
4. Insertion of linked list
int insert(linklist j,int i,int t)//i For the location to insert ,t Is the number to insert
{
int j;
linklist p,t;
p=j;
j=1;
while(p!=NULL&&j<i)
{
p=p->next;
j++;
}
if(p==NULL||j>i)// The first i There are no elements
return 0;
t=(linklist *)malloc(sizeof(struct node));
t->data=e;
t->next=p->next;// Backwards and forwards
p->next=t;
return 1;
}
The first interpolation
void creat(linklist p)
{
int n,i,m;
scanf("%d",&n);
linklist t;
p=(linklist *)malloc(sizeof(struct node));// To apply for space
p->next=NULL;// Establish a single linked list of leading nodes
for(i=0;i<n;i++)
{
scanf("%d",&m);
t=(linklist *)malloc(sizeof(struct node));
t->data=m;
t->next=p->next;
p->next=t;// Insert into the header
}
}
The tail interpolation
void creat(linklist p)
{
int n,i,m;
scanf("%d",&n);
linklist t,r;
p=(linklist *)malloc(sizeof(struct node));
r=p;//r Point to the entire linked list
for(i=0;i<n;i++)
{
scanf("%d",&m);
t=(linklist *)malloc(sizeof(struct node));
r->next=t;
r=t;// Link list
}
r->next=NULL;// End of list , The next point of the last point should be NULL
}
5. Deletion of linked list
int insert(linklist j,int i)//i For the location to insert
{
int j;
linklist p,t;
p=j;
j=1;
while(p->next!=NULL&&j<i)
{
p=p->next;
j++;
}
if(p->next==NULL||j>i)// The first i There are no elements
return 0;
t=p->next;
p->next=t->next;
free(t);
return 1;
}
边栏推荐
- 1.19 learning summary
- 1.24 learning summary
- Mobile terminal pull-down loading pull-down loading data
- Numpy general function
- [Qunhui] command line acme SH automatically apply for domain name certificate
- Construction of art NFT trading platform | NFT mall
- Ueeditor automatically appends P tags to rich text.br tags always wrap.br tag solutions
- [Qunhui] this suite requires you to start PgSQL adapter service
- Compiling and installing phpredis extension on MAC
- Install dbeaver and connect Clickhouse
猜你喜欢
CTF serialization and deserialization
1.12 learning summary
记录一次循环引用的问题
[Qunhui] import certificate
企业的产品服务怎么进行口碑营销?口碑营销可以找人代做吗?
Resolve PHP is not an internal or external command
Advanced learning of MySQL (learning from Shang Silicon Valley teacher Zhou Yang)
Database design (3): database maintenance and optimization
Physical design of database design (2)
2.9 learning summary
随机推荐
Basic query
Resolve PHP is not an internal or external command
Zhubo Huangyu: all the precious metals you want to know are here
Thymeleaf data echo, single selection backfill, drop-down backfill, time frame backfill
Your requirements could not be resolved
Physical design of database design (2)
[H5 development] 03- take you hand in hand to improve H5 development - single submission vs batch submission with a common interface
What is the best way to store chat messages in a database? [Close] - best way to store chat messages in a database? [closed]
#微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)
Nightmare
Modify the number of Oracle connections
Tp6 is easy to tread [original]
Tips for using idea
The statistics in the MySQL field become strings, and then they are converted into numbers for sorting
mysql高级学习(跟着尚硅谷老师周阳学习)
Yapi cross domain request plug-in installation
PHP splits a string into arrays
Nabicat连接:本地Mysql&&云服务Mysql以及报错
Ueeditor automatically appends P tags to rich text.br tags always wrap.br tag solutions
Minecraft 1.16.5 生化8 模组 1.9版本 1.18版本同步