Wednesday, December 9, 2009

C Dictionary

#include

struct node
{
char data;
struct node* next;
int numChildren;
char isTerminal;
};

int main()
{
struct node* aroot = malloc(sizeof(struct node));
struct node* tmp;
int i = 0;
aroot->data = 'a';
aroot->isTerminal = 1;
aroot->numChildren = 0;
aroot->next = malloc(sizeof(struct node));
++(aroot->numChildren);
aroot->next->data = 'n';
aroot->next->isTerminal = 1;
aroot->next->numChildren = 0;
tmp = (struct node*) realloc(aroot->next,aroot->numChildren + 1);
if(tmp)
aroot->next = tmp;
++(aroot->numChildren);
(aroot->next[1]).data = 'm';
(aroot->next[1]).isTerminal = 0;
//printf("%c\n",(aroot->next[0]).data);
//printf("%c\n",(aroot->next[1]).data);
for(i=0;inumChildren;i++)
{
//if(aroot->next[i].isTerminal)
printf("%c\n",(aroot->next[i]).data);
}
}

No comments:

Blog Archive