![]() |
#2
z11456744562020-12-27 20:35
回复 楼主 z1145674456
|

#include<stdio.h>
#include<malloc.h>
typedef struct node{
int key;
struct node *next;
}nodetype;
nodetype* inicial(nodetype* base);
void print(nodetype* base);
int main(){
nodetype *base=NULL;
int n;
base=inicial(base);
print(base);
return 0;
}
nodetype* inicial(nodetype* base){
nodetype *q=NULL,*p=NULL;
int x;
q=(nodetype*)malloc(sizeof(nodetype));
base=q;
p=base;
scanf("%d",&x);
do{
p->key=x;
q=(nodetype*)malloc(sizeof(nodetype));
p->next=q;
p=p->next;
p->next=NULL;
scanf("%d",&x);
}while(x!=0);
p->next=NULL;
return base;
}
void print(nodetype* base){
nodetype *tmp=base;
while(tmp!=NULL){
printf("%d",tmp->key);
tmp=tmp->next;
}
}
#include<malloc.h>
typedef struct node{
int key;
struct node *next;
}nodetype;
nodetype* inicial(nodetype* base);
void print(nodetype* base);
int main(){
nodetype *base=NULL;
int n;
base=inicial(base);
print(base);
return 0;
}
nodetype* inicial(nodetype* base){
nodetype *q=NULL,*p=NULL;
int x;
q=(nodetype*)malloc(sizeof(nodetype));
base=q;
p=base;
scanf("%d",&x);
do{
p->key=x;
q=(nodetype*)malloc(sizeof(nodetype));
p->next=q;
p=p->next;
p->next=NULL;
scanf("%d",&x);
}while(x!=0);
p->next=NULL;
return base;
}
void print(nodetype* base){
nodetype *tmp=base;
while(tmp!=NULL){
printf("%d",tmp->key);
tmp=tmp->next;
}
}
输入 5 4 2 1 3 0 应该输出 54213
可是却输出543211726400
另一道删除节点的题,也是相同的差不多的给链表赋值,和输出也是这样的问题。
