Beispiel #1
0
        public bool Equals(IntList list)
        {
            if (Length() != list.Length())
            {
                return(false);
            }

            IntNode curr1 = head;
            IntNode curr2 = list.Head();

            if (curr1 == null && curr2 == null)
            {
                return(true);
            }
            else if (curr1 == null && curr2 != null)
            {
                return(false);
            }
            else if (curr1 != null && curr2 == null)
            {
                return(false);
            }

            while (curr1 != null)
            {
                if (curr1.Data != curr2.Data)
                {
                    return(false);
                }
                curr1 = curr1.Next;
                curr2 = curr2.Next;
            }

            return(true);
        }
Beispiel #2
0
        public void AddRange(int index, IntList list)
        {
            if (index < 0 || index >= Length())
            {
                System.Console.WriteLine("Index nije unutar niza!");
                return;
            }

            IntNode curr = list.Head();

            if (head != null)
            {
                int i = index;

                while (curr != null)
                {
                    Add(i, curr.Data);
                    i++;
                    curr = curr.Next;
                }
            }
            else
            {
                while (curr != null)
                {
                    AddLast(curr.Data);
                    curr = curr.Next;
                }
            }
        }
Beispiel #3
0
        public void AddRangeLast(IntList list)
        {
            IntNode curr = list.Head();

            while (curr != null)
            {
                AddLast(curr.Data);
                curr = curr.Next;
            }
        }
Beispiel #4
0
        public void AddRangeFirst(IntList list)
        {
            IntList newList = new IntList();
            IntNode curr    = list.Head();

            while (curr.Next != null)
            {
                newList.AddLast(curr.Data);
                curr = curr.Next;
            }

            newList.AddLast(curr.Data, head);
            head = newList.Head();
        }
Beispiel #5
0
        public void Reverse()
        {
            IntList newList = new IntList();

            int k = 1;

            for (int i = 0; i < Length(); i++)
            {
                IntNode curr = head;

                for (int j = 0; j < Length() - k; j++)
                {
                    curr = curr.Next;
                }

                newList.AddLast(curr.Data);

                k++;
            }

            head = newList.Head();
        }