c语言链表把多少分以上打出来,大神帮我看一下怎么输入输出一个链表,我输入了但是没输出啊...
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
#include
#include
#include //malloc頭文件
struct Student //定義結構體
{
int num;
struct Student *next; //指向下一個數據節點的指針
};
int n;
struct Student *creat() //定義建立鏈表的函數
{
n=0;
struct Student *p1,*p2,*head;
p1=p2=(struct Student *)malloc(sizeof(struct Student)); //malloc分配動態內存
scanf("%d",&p1->num); //sizeof判斷數據類型或者表達式長度
head=NULL; //分配頭指針為空
while(p1->num!=0)
{
++n;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct Student *)malloc(sizeof(struct Student)); //開辟新的動態內存
scanf("%d",&p1->num);
};
p2->next=NULL;
return (head); //返回鏈表頭地址
};
void print(struct Student *head) //輸出函數
{
struct Student *p;
printf("數字鏈表內容為:\n");
p=head;
if(head!=NULL)
{
do
{
printf("%d\n",p->num);
p=p->next;
}while(p!=NULL);
}
}
int main() //主函數
{
struct Student *pt;
pt=creat(); //調用建立鏈表的函數
print(pt); //調用輸出鏈表的函數
return 0;
};
總結
以上是生活随笔為你收集整理的c语言链表把多少分以上打出来,大神帮我看一下怎么输入输出一个链表,我输入了但是没输出啊...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言strcpy错误,C语言中的Pri
- 下一篇: C语言时间管理小程序,写了一个时间管理的