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); }
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; }
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; }
public void RemoveFirst() { if (head == null) { return; } length--; head.Prev.Next = head.Next; head.Next.Prev = head.Prev; head = head.Next; }
public void RemoveLast() { if (head == null) { return; } length--; IntNode tail = head.Prev; tail.Prev.Next = tail.Next; tail.Next.Prev = tail.Prev; }
public void Clear() { if (head == null) { return; } length = 0; IntNode curr = head; while (curr != null) { curr.Prev = null; } }
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; }
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); }
// 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(); }
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); }
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); }
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); }
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); }
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; }
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); }
public IntList() { head = null; length = 0; }