struct node{int data;struct node *next;};struct node *create(){struct node *p;p=(struct node *)malloc(sizeof(struct node));p->next=0;return p;}main(){struct node *head,*q,*p,*t;int i;int x;head=create();for(i=1;i<=10;i++){printf("please input data:");scanf("%d",&x);q=create();q->data=x;if(i==1){head->next=q;p=q;}else{p->next=q;p=q;}}}
2 回答
慕桂英3389331
TA贡献2036条经验 获得超8个赞
#include<stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; struct node *create() { struct node *p; p=( struct node *) malloc ( sizeof ( struct node)); p->next=0; return p; } void show(node *head) { head=head->next; while (head!=NULL) { printf ( "%d\n" ,head->data); head=head->next; } } void main() { struct node *head,*q,*p,*t; int i; int x; head=create(); for (i=1;i<=10;i++) { printf ( "please input data:" ); scanf ( "%d" ,&x); q=create(); q->data=x; if (i==1) { head->next=q; p=q; } else {p->next=q; p=q;} } show(head); } |
- 2 回答
- 0 关注
- 69 浏览
添加回答
举报
0/150
提交
取消