从入门到入坑 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日

悬赏问题

  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取