2010-09-15, 08:17 PM
Code:
int compare(struct integer *p, struct integer *q)
{
int j;
while (p != NULL){
if(q==NULL){
return 1;}
else if (q!=NULL){
if (p>q){
j=1;}
else if (p<q){
j= -1;}
else if (p==q){
j= 0;}
}
p= p->next;
q= q->next;
}
return (j);
}Code:
int compare(struct integer *p, struct integer *q)
{
int c;
if (p == NULL) return -1;
if (q == NULL) return 1;
// or vice versa
if (p->next != NULL && q -> next != NULL) {
c = compare(p->next, q->next);
if (c == 0) {
if (p > q) return 1;
if (q > p) return -1;
else return 0;
}
else return c;
}
else return 0;
}returns all -1s, which is wrong for the first, third, and last ones. The only thing i changed in your code was i added a semicolon after c = compare(p->next, q->next) since it wouldnt let me compile, and capitalized the null to NULL. And I declared c, since it was undeclared.

