Exemple #1
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);
        }
Exemple #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);
        }
Exemple #3
0
        public static IntNode BuildIntList(int numbeelements)//בונה רשימה
        {
            Random  R     = new Random();
            IntNode first = new IntNode(R.Next(1, 11));
            IntNode P;

            for (int i = 0; i < numbeelements - 1; i++)
            {
                P = new IntNode(R.Next(10, 100));
                P.SetNext(first);
                first = P;
            }
            return(first);
        }
Exemple #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);
        }