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 關注
- 106 瀏覽
添加回答
舉報
0/150
提交
取消
