69,373
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
}node;
void main()
{
struct node num,* head, * p=head;
//int ordinal=1,remain=13;
//开辟13个节点
//在节点里存入数据num:1~13
if(p!=NULL) printf("Not NULL...\n");
printf("%d ",p->num);
for(int i=0;i<13;i++)
{
p->num=i+1;
printf("%d ",p->num);
p=p->next;
}
p=NULL;
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
}node;
int main(void)
{
//struct node num,* head, * p=head;
struct node num, *head, *tail, *p;
//int ordinal=1,remain=13;
//开辟13个节点
//在节点里存入数据num:1~13
//if(p!=NULL) printf("Not NULL...\n");
//printf("%d ",p->num);
head = NULL;
for(int i=0;i<13;i++)
{
p = (struct node *)malloc(sizeof(struct node));
if (!p)
exit(0);
if (!head)
head = p;
else
tail->next = p;
p->num=i+1;
printf("%d ",p->num);
tail = p;
//p=p->next;
}
p->next = NULL;
p = head;
while (p) {
printf("%d ",p->num);
p = p->next;
}
printf("\n");
return 0;
}
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct node
{
int num;
struct node *next;
}node;
void main()
{
struct node num,* head, * p,*q;
//int ordinal=1,remain=13;
//开辟13个节点
//在节点里存入数据num:1~13
head = (struct node *)malloc(sizeof(struct node));
head->next = NULL;
q = head;
if(q!=NULL) printf("Not NULL...\n");
//printf("%d ",p->num);
for(int i=0;i<13;i++)
{
p = (struct node *)malloc(sizeof(struct node));
p->num=i+1;
p->next=NULL;
q->next=p;
q=p;
printf("i=%d,%d\n",i,p->num);
//p=p->next;
}
q=head->next;
while(q){
printf("%d\n",q->num);
q=q->next;
}
//p=NULL;
system("pause");
}