public static int numberofrezef(int num, IntNode n)//תרגיל 2 { int counter = 0; IntNode i = n; IntNode bl = null; while (i.HasNext() != false) { if (i.GetNext().HasNext() == false) { bl = i; } if (i.GetValue() == num && i.GetNext().GetValue() != num) { counter++; } i = i.GetNext(); } if (bl.GetValue() != num && bl.GetNext().GetValue() == num) { counter++; } return(counter); }
public static IntNode T6(IntNode n)//תרגיל 6 { IntNode p = n; IntNode first = n; IntNode a = n; while (p != null) { while (a != null) { if (!a.HasNext()) { break; } if (a.GetNext().GetValue() == p.GetValue() && a.GetNext() != p) { a.SetNext(a.GetNext().GetNext()); } else { a = a.GetNext(); } } a = n; p = p.GetNext(); } return(first); }
public static string oddevensame(IntNode n)//תרגיל 4 { int countodd = 0; int counteven = 0; IntNode i = n; IntNode bl = null; while (i.HasNext() != false) { if (i.GetNext().HasNext() == false) { bl = i; } if (i.GetValue() % 2 == 0) { counteven++; } else { countodd++; } i = i.GetNext(); } if (bl.GetNext().GetValue() % 2 == 0) { counteven++; } else { countodd++; } if (countodd > counteven) { return("e"); } else if (countodd < counteven) { return("z"); } else { return("s"); } }