コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public static IntNode removenode(IntNode n, int num)//תרגיל 5
        {
            IntNode i = n;

            while (i.GetNext().HasNext())
            {
                if (i.GetNext().GetValue() == num)
                {
                    i.SetNext(i.GetNext().GetNext());
                }
                else
                {
                    i = i.GetNext();
                }
            }

            if (i.GetNext().GetValue() == num)
            {
                i.SetNext(null);
            }

            if (n.GetValue() == num)
            {
                n = n.GetNext();
            }

            return(n);
        }
コード例 #4
0
        public static IntNode noduoble(IntNode n)//תרגיל 6
        {
            IntNode i    = n.GetNext();
            IntNode newn = new IntNode(n.GetValue());
            IntNode a    = newn;

            while (i != null)
            {
                Console.WriteLine(i.GetValue());
                if (!isappear(newn, i.GetValue()))
                {
                    a.SetNext(new IntNode(i.GetValue()));
                    a = a.GetNext();
                }
                i = i.GetNext();
            }
            return(newn);
        }
コード例 #5
0
        public static bool isappear(IntNode n, int num)//בודק אם המספר נמצא ברשימה
        {
            IntNode i = n;

            while (i != null)
            {
                if (i.GetValue() == num)
                {
                    return(true);
                }
                i = i.GetNext();
            }
            return(false);
        }
コード例 #6
0
        public static void between(IntNode n, int num1, int num2)//תרגיל 3
        {
            IntNode j = n;

            for (int i = 0; i <= num1; i++)
            {
                j = j.GetNext();
            }
            for (int i = num1; i < num2 - 1; i++)

            {
                Console.Write(j.GetValue());
                j = j.GetNext();
            }
        }
コード例 #7
0
        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");
            }
        }