Value and type of last evaluated expression: Address of array element: Address of array elementx: (none)
Your browser does not support the canvas element
which will make some the features unavailable.
If you are using Internet Explorer within the University of Exeter
try going to the Settings menu (probably the gear shape at the top right
of this page),
selecting "Compatibility View settings",
unchecking "Display intranet sites in Compatibility View"
and reloading this page.
Code
Header...
// INCOMPLETE
// Very simple binary tree
#define N 8
typedef struct tree {
struct tree *before;
struct tree *after;
char string[N];
}Tree;
// Add a node to the tree, return the base of the tree;
» if (base) {
» if (strcmp(string, base->string)==0) {
»fprintf(stderr, "Repeated string %s\n", string);
» return base;
}
» if (base->before!=NULL&&strcmp(string, base->before->string)<0) {
»addstring(base->before, string);
» return base;
}
else if (base->after!=NULL&&strcmp(string, base->after->string)>0) {
»addstring(base->after, string);
» return base;
}
}
// We need to put a new entry here
» Tree *tmp;
»tmp=xmalloc(sizeof *tmp);
»tmp->before=tmp->after=NULL;
»tmp->string(N-1)='\0';
» if (base==NULL) {// First node in tree
»strncpy(tmp->string, string, N-1);
» return tmp;
}
» if (strcmp(string, base->string)>0) {
// new word is after base
» if (base->after==NULL) {
// Insert new word beneath
»base->after=tmp;
»strncpy(tmp->string, string, N-1);
}
else {
// Put new text in current base node, insert tmp beneath and before it
»strncpy(tmp->string, base->string, N-1);
»strncpy(base->string, string, N-1);
»tmp->before=base->before;
»base->before=tmp;
}
}
else {
» if (base->before==NULL) {
»base->before=tmp;
»strncpy(tmp->string, string, N-1);
}
else {
»strncpy(tmp->string, base->string, N-1);
»strncpy(base->string, string, N-1);
»tmp->after=base->after;
»base->after=tmp;
}
}
» return base;