当前位置:网站首页>Pointer linked list
Pointer linked list
2022-06-28 03:56:00 【I am already furious!】
Pointer list
First in first out linked list
hold p Pointer to L The head pointer of , Then create q Pointer space , Assign a value , And then p The next bit of the pointer takes q, And then put p Pointer backward , Add one at the end p->next=NULL;
#include<bits/stdc++.h>
#define bug(a) (cout<<'*'<<a<<endl)
using namespace std;
typedef struct node
{
int data;
node* next;
}*linklist;
void create(linklist& L, int n)
{
linklist p, q;
int num;
L = (linklist)malloc(sizeof(node));
p = L;
while (n--)
{
q = (linklist)malloc(sizeof(node));
scanf("%d", &num);
q->data = num;
p->next = q;
p = p->next;
}
p->next = NULL;
}
void print(linklist L)
{
L = L->next;
while (L)
{
printf("%d", L->data);
if (L->next != NULL)
printf(" -> ");
L = L->next;
}
printf("\n");
}
int main()
{
linklist l;
printf(" Please enter the number of nodes to create \n");
int n, num;
scanf("%d", &n);
printf(" Please enter the values of the nodes in turn \n");
create(l, n);
print(l);
return 0;
}
First in and last out linked list pointer
The first in and then out linked list is the opposite , First p=NULL; And then to q Create space to give value , Re order q->next=p; Always be the first , Want to be upside down .
Insert it here #include<bits/stdc++.h>
#define bug(a) (cout<<'*'<<a<<endl)
using namespace std;
typedef struct node
{
int data;
node* next;
}*linklist;
void create(linklist& L, int n)
{
linklist p, q;
p = NULL;
int num;
while (n--)
{
q = (linklist)malloc(sizeof(node));
scanf("%d", &num);
q->data = num;
q->next = p;
p = q;// From the back to the front
}
L = (linklist)malloc(sizeof(node));
L->next = p;
}
void print(linklist L)
{
L = L->next;
while (L)
{
printf("%d", L->data);
if (L->next != NULL)
printf(" -> ");
L = L->next;
}
printf("\n");
}
int main()
{
linklist l;
printf(" Please enter the number of nodes to create ( First in, then out )\n");
int n, num;
scanf("%d", &n);
printf(" Please enter the values of the nodes in turn \n");
create(l, n);
print(l);
return 0;
}
边栏推荐
- 猴子都会用的圆形滑动自动吸附UI工具
- 一千行 MySQL 学习笔记,值得收藏!
- Scalable storage system (I)
- 多线程与高并发五:等待队列及Executor和线程池详解(重点)
- Change of monitoring documents and folders of "operation and maintenance department"
- 解析教育机器人的综合应用能力
- Execution plan in MySQL of database Series
- ambari SSLError: Failed to connect. Please check openssl library versions.
- Sublime text 3 basic configuration tutorial
- 自用工具 猴子都会用的unity视频播放器
猜你喜欢
随机推荐
Li Kou daily question - day 29 -575 Divide candy
Simple implementation of cool GUI window based on WPF
一文告诉你什么是 Kubernetes
The operating mechanism of spectrogram in audio Science
ambari SSLError: Failed to connect. Please check openssl library versions.
月赛补题
Floating point and complex type of go data type (4)
Arrangement of basic electrical knowledge (II)
资源管理、高可用与自动化(下)
Does the applet image component not display pictures?
资源管理、高可用与自动化(中)
STM32外设SDIO和SD卡的配置
leetcode:单调栈结构(进阶)
django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
How to automatically add author, time, etc. to eclipse
物体上下漂浮工具
Learning - useful resources
ambari SSLError: Failed to connect. Please check openssl library versions.
自用工具 猴子都会用的unity视频播放器
小程序image组件不显示图片?









