rapirapp
BAN USER- 2of 2 votes
AnswersHow can we implement spell checker.
- rapirapp in United States| Report Duplicate | Flag | PURGE
Amazon SDE1 Algorithm Data Structures
We can use vector class
class Vector
{
public Node[] child = new Node[1];
public int count = 0;
public void add(string name)
{
if (count < child.Length)
{
child[count++] = new Node(name);
}
else
{
resize();
child[count++] = new Node(name);
}
}
public void delete(int index)
{
Node[] tmp = new Node[1];
count = 0;
for (int i = 0; i < child.Length; i++)
{
if (i != index)
{
tmp[count++] = child[i];
}
}
child = tmp;
}
public void resize()
{
Node[] tmp = new Node[child.Length * 2];
for (int i = 0; i < child.Length; i++)
{
tmp[i] = child[i];
}
child = tmp;
}
public void travers()
{
for (int i = 0; i < count; i++)
{
Console.Write(child[i].name + " ");
}
Console.WriteLine();
}
}
class Node
{
public string name;
public Node parent;
public Node() { }
public Node(string name) { this.name = name; }
}
Ok Amit let's understand what is the difference between min heap and max heap. In the first one uses ascending priority where the smallest item is the first to be popped from the heap. A max heap uses descending priority where the largest item is the first to be popped.
- rapirapp June 27, 2013
ok I don't say that Amit is not right but I want to understand why is Amit right.
- rapirapp June 27, 2013