#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;
麻煩大家幫忙看看,謝謝!
uj5u.com熱心網友回復:
head是野指標uj5u.com熱心網友回復:
暫停運行是指什么?參考樓主的代碼修改,生成帶頭節點的13個節點的鏈表,同時往里存入1-13,供參考:#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");
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/277849.html
標籤:C語言
上一篇:多項式求和
下一篇:輸入一組數字 排序后輸出結果
