在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/C  Office/ 想插入鏈表,怎么無法運(yùn)行

想插入鏈表,怎么無法運(yùn)行

#include<stdio.h>
struct a
{
        int element;
        struct a *next;
};
void insert(int a,struct a *P)
{
    struct a *TmpCell;
    TmpCell =(struct a*)malloc(10);
    TmpCell->element=a;
    TmpCell->next=P->next;
    P->next=TmpCell;
}
int main(void)
{
    int b=1;
    struct a *P;
    P->next=NULL;
    insert(b,P);
    return 0;



}
回答
編輯回答
悶騷型

起碼貼一下運(yùn)行日志啊。
目前我看到的錯(cuò)誤有三個(gè)地方
malloc 函數(shù)需要引入 stdlib.h
main函數(shù)中的指針P沒有初始化
TmpCell =(struct a*)malloc(10); 這里這樣寫不合理
TmpCell =(struct a*)malloc(sizeof(struct a)); 更好一些

2018年4月11日 03:02