/(1) 编写程序sy12-1.cpp,函数Creatlink的功能是创建带头结点的单向链表,并为各结点数据域赋0到m-1的值。请完善函数Creatlink的函数体,使该程序能得出正确的结果。/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct aa
{ int data;
struct aa *next;
} NODE;
NODE *Creatlink(int n, int m) //创建带头结点的单链表
{
NODE *h=NULL,*p,s;
int i=1;
s = (NODE)malloc(sizeof(NODE));
h=s;
p=s;
for(i=0;i<n;i++)
{
s= (NODE*)malloc (sizeof (NODE)) ;
s->data = rand()%(m-1);
s->next=p->next;
p->next=s;
p=p->next;
}
s->next = NULL;
return h;
}
void outlink(NODE *h) //输出链表
{ NODE *p;
p=h->next;
printf("\n\nTHE LIST :\n\n HEAD “);
while§
{ printf(”->%d “,p->data);
p=p->next;
}
printf(”\n");
}
void main()
{ NODE head;
head=Creatlink(8,22);
outlink(head);
}
/(2) 设计程序sy12-2.cpp,给定程序中,函数fun的功能是将不带头节点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为:10、4、2、8、6,排序后链表结点数据域从头至尾的数据为:2、4、6、8、10。 */
#include <stdio.h>
#include <stdlib.h>
#define N 6
typedef struct node
{ int data;
struct node *next;
} NODE;
void fun(NODE *h)
{