当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
如何系统学习一门编程语言? | 黑马程序员
STM32 peripheral SDIO and SD card configuration
第九章 APP项目测试(3) 测试工具
gcd最大公约数
数字电路学习笔记(二)
Li Kou daily question - day 29 -1491 Average wage after removing minimum wage and maximum wage
多线程与高并发三:AQS底层源码分析及其实现类
开口式霍尔电流传感器如何助力直流配电改造?
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
Websocket (simple experience version)
力扣每日一题-第29天-523.在区间范围统计奇数数目
django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
How the uni app automatically switches the requested address according to the environment
Floating point and complex type of go data type (4)
Li Kou daily question - day 29 -523 Count odd numbers in interval range
电子地图坐标系统研究整理
多线程与高并发四:VarHandle与强软弱虚引用和ThreadLocal
ambari SSLError: Failed to connect. Please check openssl library versions.
TypeScript 联合类型
小程序输入框闪动?