数据结构的一点小问题(初学者)
#include<stdio.h>
#include<stdlib.h>
typedef struct Rain{int data; struct Rain*link;}test;
Rain *p,*q,*r,*head;
int L;
int m=sizeof(test);
void build();
void display();
int insert_int(int,int);
int delet_char(int);
/*----------------------------------------*/
void build()
{int i;
head=(test*)malloc(m);
p=head;
for(i=1;i<L;i++)
{P->data=i+'0'-1;
p->link=(test*)molloc(m);
p=p->link;}
P->data=i+'0'-1;
p->link=NULL;
}
/*--------------------------------------------*/
void display()
{p=head;
while (p->link!=NULL)
{printf("%d",p->data);
p=p->link;}
printf("%d\n",p->data);
}
/*-------------------------------------------*/
int insert_int(int X,int Y)
{p=head;
r=(test*)molloc(m);
r->data=X;
if(head->data==Y)
{head=r;
r->link=p;
}
else { while ((p->data!=Y)&&(p->link!=NULL)){q=p; p=p->link;}
if(p->data==Y ) {q->link=r;r->link=p;}
else {p->link=r; r->link=NULL;}
}
L++;
return(0);
}
/*---------------------------------------------*/
int delet_int(int X)
{p=head ;
if(head->data==X) {head=head->link; free(p);}
else { while ((p->data!=X)&&(p->link!=NULL))
{ q=p;
p=p->link;
if (p->data==X)
{q->link=p->link;
free(P);}
else return(-1);
}
L--;
return (0);
}
/*---------------------------------------------*/
void main(void)
{ L=9;
build();
display();
printf("insert return value =%d\n",insert_int('7','8');
display();
printf ("delete return value=%d\n",delet_int('3'));
display();
}
不知道为什么错了,小子这里向大家虚心求教啦
[解决办法]
void build() { int i; head=(test*)malloc(m); p=head; [color=#FF0000]//定义了??[/color] for(i=1;i<L;i++) { P->data=i+'0'-1; //P p->link=(test*)molloc(m); //P,一会大写,一会小写,你牛. p=p->link;} P->data=i+'0'-1; p->link=NULL; }
[解决办法]
多少分数呀,你发给我,我给你调试,给我分数呀,呵呵,我的qq
935727586
[解决办法]
#include<stdio.h>#include<stdlib.h>typedef struct Rain{ int data; struct Rain*link;}test; Rain *p,*q,*r,*head; int L; int m=sizeof(test); void build(); void display(); int insert_int(int,int); int delet_char(int); /*----------------------------------------*/ void build() { int i; head=(test*)malloc(m); p=head; for(i=1;i<L;i++) { p->data=i+'0'-1; p->link=(test*)malloc(m); p=p->link; } p->data=i+'0'-1; p->link=NULL; } /*--------------------------------------------*/ void display() { p=head; while (p->link!=NULL) { printf("%d",p->data); p=p->link; } printf("%d\n",p->data); }/*-------------------------------------------*/ int insert_int(int X,int Y) { p=head; r=(test*)malloc(m); r->data=X; if(head->data==Y) { head=r; r->link=p; } else { while ((p->data!=Y)&&(p->link!=NULL)) { q=p; p=p->link; } if(p->data==Y ) {q->link=r;r->link=p;} else {p->link=r; r->link=NULL;} } L++; return(0);}/*---------------------------------------------*/int delet_int(int X){ p=head ; if(head->data==X) { head=head->link; free(p); } else { while ((p->data!=X)&&(p->link!=NULL)) { q=p; p=p->link; if (p->data==X) { q->link=p->link; free(p); } else return(-1); } } L--; return (0);} /*---------------------------------------------*/int main(){ L=cript>
[解决办法]
#include<stdio.h>#include<stdlib.h>typedef struct Rain{ int data; struct Rain*link;}test; Rain *p,*q,*r,*head; int L; int m=sizeof(test); void build(); void display(); int insert_int(int,int); int delet_char(int); /*----------------------------------------*/ void build() { int i; head=(test*)malloc(m); p=head; for(i=1;i<L;i++) { p->data=i+'0'-1; p->link=(test*)malloc(m); p=p->link; } p->data=i+'0'-1; p->link=NULL; } /*--------------------------------------------*/ void display() { p=head; while (p->link!=NULL) { printf("%d",p->data); p=p->link; } printf("%d\n",p->data); }/*-------------------------------------------*/ int insert_int(int X,int Y) { p=head; r=(test*)malloc(m); r->data=X; if(head->data==Y) { head=r; r->link=p; } else { while ((p->data!=Y)&&(p->link!=NULL)) { q=p; p=p->link; } if(p->data==Y ) {q->link=r;r->link=p;} else {p->link=r; r->link=NULL;} } L++; return(0);}/*---------------------------------------------*/int delet_int(int X){ p=head ; if(head->data==X) { head=head->link; free(p); } else { while ((p->data!=X)&&(p->link!=NULL)) { q=p; p=p->link; if (p->data==X) { q->link=p->link; free(p); } else return(-1); } } L--; return (0);} /*---------------------------------------------*/int main(){ L=9; build(); display(); printf("insert return value =%d\n",insert_int('7','8')); display(); printf ("delete return value=%d\n",delet_int('3')); display(); return 0;}