|
|
#2
林月儿2019-10-22 17:07
|
程序代码:#include<stdio.h>
#include<stdlib.h>
typedef int elemtype;
typedef struct Node{
elemtype data;
struct Node *next;
}Node,*List;
void outputlist(List L);
Node* createlist(List L,int n);
int main()
{
List h=NULL;
printf("请输入5个数:");
createlist(h,5);
outputlist(h);
return 0;
}
Node* createlist(List L,int n)
{
L=(struct Node*)malloc(sizeof(Node));
L->next=NULL;
Node *r=L;
int i;
for(i=0;i<n;i++){
Node* p=(Node*)malloc(sizeof(Node));
scanf("%d",&p->data);
p->next=NULL;
r->next=p;
r=p;
}
return L;
}
void outputlist(List L)
{
Node* p;
p=(Node*)malloc(sizeof(Node));
p=L->next;
while(p){
printf("%d ",p->data);
p=p->next;
}
}
#include<stdlib.h>
typedef int elemtype;
typedef struct Node{
elemtype data;
struct Node *next;
}Node,*List;
void outputlist(List L);
Node* createlist(List L,int n);
int main()
{
List h=NULL;
printf("请输入5个数:");
createlist(h,5);
outputlist(h);
return 0;
}
Node* createlist(List L,int n)
{
L=(struct Node*)malloc(sizeof(Node));
L->next=NULL;
Node *r=L;
int i;
for(i=0;i<n;i++){
Node* p=(Node*)malloc(sizeof(Node));
scanf("%d",&p->data);
p->next=NULL;
r->next=p;
r=p;
}
return L;
}
void outputlist(List L)
{
Node* p;
p=(Node*)malloc(sizeof(Node));
p=L->next;
while(p){
printf("%d ",p->data);
p=p->next;
}
}
[此贴子已经被作者于2019-10-27 16:01编辑过]
