#include main() { struct node{int n;struct node *nest;} *p;
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/03/29 19:08:47
#include main() { struct node{int n;struct node *nest;} *p;
#include
main()
{
struct node{int n;struct node *nest;} *p;
struct node x[3]={{2,x+1},{4,x+2},{6,NULL}};
p=x;
printf("%d\n",p->n);
printf("%d\n",p->next->n);
}
#include
main()
{
struct node{int n;struct node *nest;} *p;
struct node x[3]={{2,x+1},{4,x+2},{6,NULL}};
p=x;
printf("%d\n",p->n);
printf("%d\n",p->next->n);
}
这里是用初始化的方式定义了一个结构体链表,先说我们正常的定义链表的方式:
struct node x,*new;
x.n = 2;
new = (struct node *)malloc(sizeof(struct node));
x->next = new;
new.n = 4;
最后一个节点就不写了,做法就是申请一个节点空间,链接到第一个节点上,再进行赋值.
这里的做法也很简单,但是节点很多的情况就不适合了,对结构体元素n的赋值想必你能理解,就是赋值为2、4、6,对struct node *next赋值时用的x的地址进行偏移,它能这样做的基础就是这三个节点本身也是在同一个数组中的,所以地址可以通过x+1、x+2获取.结点1的地址:x,结点2的地址:x+1,结点3的地址:x+2,所以它要链起来直接给结点1的next赋值为x+1,给结点2的next赋值为x+2.最终就生成一个3结点链表.
struct node x,*new;
x.n = 2;
new = (struct node *)malloc(sizeof(struct node));
x->next = new;
new.n = 4;
最后一个节点就不写了,做法就是申请一个节点空间,链接到第一个节点上,再进行赋值.
这里的做法也很简单,但是节点很多的情况就不适合了,对结构体元素n的赋值想必你能理解,就是赋值为2、4、6,对struct node *next赋值时用的x的地址进行偏移,它能这样做的基础就是这三个节点本身也是在同一个数组中的,所以地址可以通过x+1、x+2获取.结点1的地址:x,结点2的地址:x+1,结点3的地址:x+2,所以它要链起来直接给结点1的next赋值为x+1,给结点2的next赋值为x+2.最终就生成一个3结点链表.
#include main() { struct node{int n;struct node *nest;} *p;
typedef struct node { int data; struct node *next; } NODE,*n
typedef struct node { int data; struct node *next; }Node,*Li
typedef struct Node { ElemType data; struct Node *next; }Nod
关于c语言,请问typedef struct {elemtype data ;struct Node *next ;}N
定义个结构node,然后typedef struct node NODE[10];是什么意思?
关于typedef struct node这一段每一句什么意思?
以下程序的输出结果是 struct HAR {int x,y; struct HAR *P;} h[2]; main()
struct S { int i; int * p;}; main () {S s ; int *p =&s.i ; p
6:以下程序的运行结果是( ).#include “stdio.h” main() {struct data {int
#include struct ord { int x,y;} dt[2]={1,2,3,4}; main() {str
#include "stdio.h" #include "conio.h" struct n {int x,y;} d[