Exemple #1
0
        public void MinFirst()
        {
            if (head == null)
            {
                return;
            }

            IntNode curr = head;
            IntNode min  = GetMin();
            uint    i    = 0;

            do
            {
                if (curr.Data == min.Data)
                {
                    AddFirst(curr.Data);
                    curr = curr.Next;
                    Remove(i);
                }
                else
                {
                    curr = curr.Next;
                }
                i++;
            } while (curr != head);
        }
Exemple #2
0
        public void Remove(uint index)
        {
            if (index > length - 1)
            {
                System.Console.WriteLine("Error: index out of bound of list.");
                return;
            }
            if (index == 0)
            {
                RemoveFirst();
                return;
            }
            if (index == length - 1)
            {
                RemoveLast();
                return;
            }
            length--;

            IntNode curr = head;

            for (int i = 0; i <= index; i++)
            {
                curr = curr.Next;
            }

            curr.Prev.Next = curr.Next;
            curr.Next.Prev = curr.Prev;
        }
Exemple #3
0
        public void Add(int data, uint index)
        {
            if (index > length - 1)
            {
                System.Console.WriteLine("Error: index out of bound of list.");
                return;
            }
            if (index == 0)
            {
                AddFirst(data);
                return;
            }
            if (index == length - 1)
            {
                AddLast(data);
                return;
            }
            length++;

            IntNode curr = head;

            for (int i = 0; i <= index; i++)
            {
                curr = curr.Next;
            }

            IntNode element = new IntNode(data, curr.Prev.Next, curr.Prev);

            curr.Prev.Next = element;
            curr.Prev      = element;
        }
Exemple #4
0
        public void RemoveFirst()
        {
            if (head == null)
            {
                return;
            }
            length--;

            head.Prev.Next = head.Next;
            head.Next.Prev = head.Prev;
            head           = head.Next;
        }
Exemple #5
0
        public void RemoveLast()
        {
            if (head == null)
            {
                return;
            }
            length--;

            IntNode tail = head.Prev;

            tail.Prev.Next = tail.Next;
            tail.Next.Prev = tail.Prev;
        }
Exemple #6
0
        public void Clear()
        {
            if (head == null)
            {
                return;
            }
            length = 0;

            IntNode curr = head;

            while (curr != null)
            {
                curr.Prev = null;
            }
        }
Exemple #7
0
        public void AddLast(int data)
        {
            length++;
            if (head == null)
            {
                head      = new IntNode(data);
                head.Next = head;
                head.Prev = head;
                return;
            }

            IntNode tail    = head.Prev;
            IntNode element = new IntNode(data, head, tail);

            tail.Next = element;
            head.Prev = element;
        }
Exemple #8
0
        public override string ToString()
        {
            string str = "";

            if (head == null)
            {
                return(str);
            }

            IntNode curr = head;

            do
            {
                str += (" " + curr.Data.ToString());
                curr = curr.Next;
            } while (curr != head);

            return(str);
        }
Exemple #9
0
        // Nije gotova
        public void Reverse()
        {
            if (head == null)
            {
                return;
            }

            IntList lista = new IntList();
            IntNode curr  = head.Prev;

            while (curr != head)
            {
                lista.AddLast(curr.Data);
                System.Console.WriteLine(curr.Data);
                curr = curr.Prev;
            }

            Clear();
            head = lista.GetFirst();
        }
Exemple #10
0
        public IntNode FindAndGet(int data)
        {
            if (head == null)
            {
                return(null);
            }

            IntNode curr = head;

            do
            {
                if (curr.Data == data)
                {
                    return(curr);
                }
                curr = curr.Next;
            } while (curr != head);

            return(null);
        }
Exemple #11
0
        public bool Find(int data)
        {
            if (head == null)
            {
                return(false);
            }

            IntNode curr = head;

            do
            {
                if (curr.Data == data)
                {
                    return(true);
                }
                curr = curr.Next;
            } while (curr != head);

            return(false);
        }
Exemple #12
0
        public IntNode GetMin()
        {
            if (head == null)
            {
                return(null);
            }

            IntNode curr = head;
            IntNode min  = head;

            do
            {
                if (curr.Data < min.Data)
                {
                    min = curr;
                }
                curr = curr.Next;
            } while (curr != head);

            return(min);
        }
Exemple #13
0
        public IntNode GetMax()
        {
            if (head == null)
            {
                return(null);
            }

            IntNode curr = head;
            IntNode max  = head;

            do
            {
                if (curr.Data > max.Data)
                {
                    max = curr;
                }
                curr = curr.Next;
            } while (curr != head);

            return(max);
        }
Exemple #14
0
        public void Megre(IntList lista)
        {
            if (head == null)
            {
                head = lista.GetFirst();
                return;
            }
            if (lista == null)
            {
                return;
            }

            IntNode thisTail = head.Prev;
            IntNode thisHead = head;
            IntNode newTail  = lista.GetLast();
            IntNode newHead  = lista.GetFirst();

            thisTail.Next = newHead;
            newHead.Prev  = thisTail;
            newTail.Next  = thisHead;
            thisHead.Prev = newTail;
        }
Exemple #15
0
        public void RemoveDuplicates()
        {
            if (head == null)
            {
                return;
            }

            IntNode curr = head;
            uint    i    = 0;

            do
            {
                if (FindAndGet(curr.Data) != curr)
                {
                    curr = curr.Next;
                    Remove(i);
                }
                else
                {
                    curr = curr.Next;
                    i++;
                }
            } while (curr != head);
        }
Exemple #16
0
 public IntList()
 {
     head   = null;
     length = 0;
 }