Bagrut Questions

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

public static int numNodesFollowing(Node<int> indicator)

{
int c = 0;

while(indicator != null)
{
c++;
indicator =indicator.GetNext();
}
return c;
}

______________________________________________________________________

public static bool IsSection(Node<int> list)


{
Node<int> p = list;
while(p!=null)
{
if (p.GetValue() > numNodesFollowing(p.GetNext()))
return false;

p=p.GetNext();

}
return true;

}
public static Node<int> Build(Node<int> lst) // bagrut
{

Node<int> newLst = null;


Node<int> p = lst;
Node<int> temp = null;

while (p != null)
{
int value = p.GetValue();

while (value > 0)


{
int digit = value % 10;

if (newLst == null)
{
newLst = new Node<int>(digit);
temp = newLst;
}
else
{
temp.SetNext(new Node<int>(digit));
temp = temp.GetNext();
}

value = value / 10;


}

temp.SetNext(new Node<int>(-9));
temp = temp.GetNext();

p = p.GetNext();
}

return newLst;
}

You might also like