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

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

问题描述:

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

//尝试写一下链表的头插法
#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;
}


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