当前位置:网站首页>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;
}
边栏推荐
- 数据库系列之MySQL和TiDB中慢日志分析
- Custom controls under WPF and adaption of controls in Grid
- 开口式霍尔电流传感器如何助力直流配电改造?
- Leetcode: monotonic stack structure (Advanced)
- 英语小记 - 表因果
- Resource management, high availability and automation (medium)
- leetcode:单调栈结构(进阶)
- Floating point and complex type of go data type (4)
- STM32 peripheral SDIO and SD card configuration
- ambari SSLError: Failed to connect. Please check openssl library versions.
猜你喜欢
黑体辐射初探
开关电源—Buck电路原理及其仿真
多线程与高并发三:AQS底层源码分析及其实现类
资源管理、高可用与自动化(中)
数字有为,易步到位 华为携“5极”明星产品加速布局商业市场
可扩展存储系统(上)
applicationContext.getBeansOfType 获取一个接口下所有实现类 执行方法或者获取实现类对象等 操作应用场景学习总结
Websocket (simple experience version)
leetcode:494. All methods of adding and subtracting operators to the array to get the specified value
第九章 APP项目测试(3) 测试工具
随机推荐
小程序输入框闪动?
自用工具 猴子都会用的unity视频播放器
测不准原理
Self use tool unity video player that monkeys can use
uni-app 如何根据环境自动切换请求的地址
STM32 peripheral SDIO and SD card configuration
机器人编程教育的市场竞争力
leetcode:494.数组中添加加减运算符得到指定值的所有方法
Pycharm setting pseudo sublime color scheme
月赛补题
English语法_形容词/副词3级-比较级_常用短语
A preliminary study of blackbody radiation
iptables防火墙规则和firewalld防火墙规则详解
开启创客教育造物学的领域
以自动化赋能转型,飞鹤乳业加速迈向数字化!
「运维有小邓」监控文件及文件夹变更
电学基础知识整理(一)
TypeScript 联合类型
Simple implementation of cool GUI window based on WPF
Paging query optimization in MySQL of database Series