64,681
社区成员
发帖
与我相关
我的任务
分享
#include "iostream"
#include "string"
#include <stdlib.h>
using std::cin;
using std::cout;
using std::endl;
typedef struct Node
{
int data;
struct Node *next;
}Node;
typedef struct Node *LinkList;
LinkList CreatListHead(LinkList *L,int n)
{
int i=0,temp=0;
LinkList p;
(*L)=(LinkList)malloc(sizeof(Node));
(*L)->next=NULL;
(*L)->data=99;
for(i=0;i<n;i++)
{
p=(LinkList)malloc(sizeof(Node));
cin>>temp;
p->data=temp;
p->next=(*L)->next;
(*L)->next=p;
}
return *L;
}
int main()
{
LinkList L,p;
p=CreatListHead(&L,10);
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
}