Answer the question
In order to leave comments, you need to log in
What do the parts of this code mean?
Hello!
I apologize that without the code tag (I write the code on a virtual machine)
The function in the picture looks for a name in an array of pointers to a structure of type name* table[TBLSZ]
.
If a name is found, it returns this double value. Something like variables, for a calculator
The code is an example and its author is not me, I did not understand a few things in it:
struct name {
char* string;
name* next;
double value;
};
const TBLSZ = 23;
name* table[TBLSZ];
name* look(const char* p, int ins =0)
{
int ii = 0; // хэш-код
const char* pp = p;
while (*pp) ii = ii<<1 ^ *pp++;
if (ii < 0) ii = -ii;
ii %= TBLSZ;
for (name* n=table[ii]; n; n=n->next) // поиск
if (strcmp(p,n->string) == 0) return n;
if (ins == 0) error("имя не найдено");
name* nn = new name; // занесение
nn->string = new char[strlen(p)+1];
strcpy(nn->string,p);
nn->value = 1;
nn->next = table[ii];
table[ii] = nn;
return nn;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question