从入门到入坑 2019-12-30 09:23 采纳率: 100%
浏览 115
已采纳

请问大佬,我这个头插法写的对吗?

另外,能不能提供给我个头插法,尾插法的模板?
网上的都不太一样

//尝试写一下链表的头插法
#include
#include
struct student
{
int grade ;
struct student pnext;
};
struct student * create_list(struct student *phead);
int main()
{
struct student *phead,*ptail;
phead = NULL;
ptail = NULL;
phead = create_list(phead);
return 0;
}
struct student * create_list(struct student *phead)
{
struct student *pnew = (struct student
)malloc(sizeof(struct student));
pnew->pnext = NULL;
if(phead==NULL)
{
//phead = pnew;
ptail = pnew;

}
else
{
pnew->pnext = phead;
//phead = pnew;
}
phead = pnew;
return phead;
}


展开全部

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-12-30 16:07
    关注

    类似问题我刚回答过,你没看?
    https://ask.csdn.net/questions/1049361

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部