将代码修改为——创建的长度不定的单链表,完成链表中数据元素的输出,每行输出5个数据。程序应该怎样写呢

typedef int ElemType;
typedef struct Node
{
ElemType data;
struct Node next;
}Node, LinkList;
#include
#include
using namespace std;
int main(){
LinkList p,lp,h;
ElemType tmp;
cin>>tmp;
h=p=(LinkList) malloc(sizeof(Node)); p->data=tmp;
lp=p;
for(int i=1;i<=9;i++) {
cin>>tmp;
p=(Node *) malloc(sizeof(Node)); p->data=tmp;
lp->next=p;
lp=p;

}
lp->next=NULL;
p=h;
while(p)
{
coutnext;
}
}

typedef int ElemType;
typedef struct Node
{
ElemType data;
struct Node next;
}Node, LinkList;
#include <malloc.h>
#include
using namespace std;
int main(){
LinkList p,lp,h;
ElemType tmp;
cin>>tmp;
h=p=(LinkList) malloc(sizeof(Node)); p->data=tmp;
lp=p;
int  n;
cin>>n;
for(int i=1;i<=n;i++) {
cin>>tmp;
p=(Node *) malloc(sizeof(Node)); p->data=tmp;
lp->next=p;
lp=p;

}
lp->next=NULL;
p=h;
int k = 0;
while(p)
{
k++;
cout<data<<" "; p=p->next;
if(k%5==0)
cout<<endl;
}
}