从入门到入坑 2019-12-30 17: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-31 00:07
    关注

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

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

报告相同问题?

问题事件

  • 已采纳回答 12月10日

悬赏问题

  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝