链表的基本操作-创建一个链表

有一链式结构,定义如下 :

struct stu{

char name[20];

int no;

struct stu *next;

};

创建一个函数create(),实现无头结点的链表,有m个结点,函数的返回值为链表的头指针。
函数接口定义:


在这里描述函数接口。例如:
struct stu * create()

在这里解释接口参数。在函数中输入m,及m行数据,完成链表的创建。

在这里给出函数被调用进行测试的例子。例如:
#include 
#include 

struct stu{
   char name[20];
     int no;
     struct stu *next;};
struct stu * create();
void show(struct stu *p){
  while(p){
       printf("%s %d\n",p->name,p->no);
       p=p->next;
     }
     }
int main()
{

  struct stu *p=NULL;
    p=create();
     show(p);
  return 0;

}

/* 请在这里填写答案 */


输入样例:
在这里给出一组输入。例如:

2
liming 23
maming 35
输出样例:
在这里给出相应的输出。例如:

liming 23
maming 35

struct stu * create()
{
    struct stu *head = NULL,tail = NULL;
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        struct stu *p = (struct stu*)malloc(sizeof(struct stu));
        scanf("%s%d",p->name,&p->no);
        p->next = NULL;
        if(head == NULL)
            head = p;      
        else
             tail->next = p;
        tail = p; 
    }
    return head;
}

数据结构对单链表进行数据排序 http://bbs.csdn.net/topics/392201633

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^