I just want to write code for comparing a 1D array with a 2D array… I am working on writing a compiler and want to compare a 1D array which contains my code and other 2D array in which I have made a symbol table.
I have written code, but it’s not working.
for (int x = 0; x < symboltable1.Length; x++)
{
for (int y = 0; y < symboltable1.Length; y++)
{
for (int z = 0; z < text.Length; z++)
{
if (symboltable1[x,y] == text[z])
listBox2.Items.Add(text[z]);
else
MessageBox.Show("poor");
}
}
}
Your method is too slow O(n*m*l) (where l is the length of text,n & m the dimensions of your symboltable.)
Transforming your symboltable into a sorted indexed table would give you an O(l*log(n*m)), and using a hashtable instead would give you an almost O(l).
I’ve implemented the three approach just for fun: