-1

I have a program that reads in strings from a text file and then stores them in an AVL tree, I also have to remove nodes and insert new ones from the command line. I understand how to do this when the nodes have ints as keys, but mine are strings.

How should I tackle this?

typedef struct Node {
    int height;
    int count;
    char key[10];
    struct Node * left;
    struct Node * right;
} Node;
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
Santi GS
  • 87
  • 1
  • 3
  • 9

1 Answers1

0

I understand how to do this when the nodes have ints as keys, but mine are strings.

The same, you just need to change the comparison function (compare strings instead of integers), something like:

static int comp_by_key(const void *pa, const void *pb)
{
    const Node *a = pa, *b = pb;

    return strcmp(a->key, b->key);
}
David Ranieri
  • 39,972
  • 7
  • 52
  • 94