bob
unknown
csharp
2 years ago
1.2 kB
8
Indexable
public static bool isTowNumbers(Node<int> first)// ⦁ כתוב פעלה שבודקת אם בשרשרת רק שני מספרים מתחלפים כל פעם לסרוגין
//x-> y -> x-> y
{
Node<int> p = first;
if (p == null)
{
return false;
}
int num1 = p.GetValue();
int num2 = p.GetNext().GetValue();
if (num2 == num1)
{
return false;
}
while (p.GetNext().GetNext() != null && p.GetNext().HasNext())
{
if (p.GetValue() != num1 || p.GetNext().GetValue() != num2 || p.GetNext().GetNext().GetValue() != num1)
{
return false;
}
p = p.GetNext().GetNext();
}
if (p == null)
{
return false;
}
if (p.GetValue() != num1 || p.GetNext().GetValue() != num2)
{
return false;
}
return true;
}Editor is loading...
Leave a Comment