/** * Prints out the contents of the neighborlist. */ public void printList() { if (isEmpty()) { System.out.println("Empty list"); } else { NeighborNode current = m_First; while (current != null) { System.out.println("Node: instance " + current.m_Instance + ", distance " + current.m_Distance); current = current.m_Next; } System.out.println(); } }
/** * Prints out the contents of the neighborlist. */ public void printList() { if (isEmpty()) { System.out.println("Empty list"); } else { NeighborNode current = m_First; while (current != null) { System.out.println("Node: instance " + current.m_Instance + ", distance " + current.m_Distance); current = current.m_Next; } System.out.println(); } }
if (isEmpty()) { m_First = m_Last = new NeighborNode(distance, instance); } else {
if (isEmpty()) { m_First = m_Last = new NeighborNode(distance, instance); } else {
/** * Prunes the list to contain the k nearest neighbors. If there are multiple * neighbors at the k'th distance, all will be kept. * * @param k the number of neighbors to keep in the list. */ public void pruneToK(int k) { if (isEmpty()) { return; } if (k < 1) { k = 1; } int currentK = 0; double currentDist = m_First.m_Distance; NeighborNode current = m_First; for (; current.m_Next != null; current = current.m_Next) { currentK++; currentDist = current.m_Distance; if ((currentK >= k) && (currentDist != current.m_Next.m_Distance)) { m_Last = current; current.m_Next = null; break; } } }
/** * Prunes the list to contain the k nearest neighbors. If there are multiple * neighbors at the k'th distance, all will be kept. * * @param k the number of neighbors to keep in the list. */ public void pruneToK(int k) { if (isEmpty()) { return; } if (k < 1) { k = 1; } int currentK = 0; double currentDist = m_First.m_Distance; NeighborNode current = m_First; for (; current.m_Next != null; current = current.m_Next) { currentK++; currentDist = current.m_Distance; if ((currentK >= k) && (currentDist != current.m_Next.m_Distance)) { m_Last = current; current.m_Next = null; break; } } }