In C language, string library has a function strcmp that takes two arguments and return -1, 0 or 1 depending on whether first string is less than equal-to or greater than the second string.

int strcmp(const char *str1, const char *str2);

Write similar function that compare strings given in the form of linked list, For example:

If:
First List: s->a->n->s->k->r->i->t
Second List: s->a->n->s->k->r->i->t->i
Output: -1
If:
First List: s->a->n->s->k->r->i->t
Second List: a->t->m->a->n
Output: 1
If:
First List: n->o->n->t->r->a->n->s->l->a->t->a->b->l->e
Second List: n->o->n->t->r->a->n->s->l->a->t->a->b->l->e
Output: 0

The signature of function will change like as shown below:

int strcmp(Node *head1, Node *head2);

Continue reading »