zoukankan      html  css  js  c++  java
  • java语言特性之一

    package java.util.Collections;

    public static int indexOfSubList(List<?> source, List<?> target) {
    int sourceSize = source.size();
    int targetSize = target.size();
    int maxCandidate = sourceSize - targetSize;

    if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||
    (source instanceof RandomAccess&&target instanceof RandomAccess)) {
    nextCand:
    for (int candidate = 0; candidate <= maxCandidate; candidate++) {
    for (int i=0, j=candidate; i<targetSize; i++, j++)
    if (!eq(target.get(i), source.get(j)))
    continue nextCand; // Element mismatch, try next cand
    return candidate; // All elements of candidate matched target
    }
    } else { // Iterator version of above algorithm
    ListIterator<?> si = source.listIterator();
    nextCand:
    for (int candidate = 0; candidate <= maxCandidate; candidate++) {
    ListIterator<?> ti = target.listIterator();
    for (int i=0; i<targetSize; i++) {
    if (!eq(ti.next(), si.next())) {
    // Back up source iterator to next candidate
    for (int j=0; j<i; j++)
    si.previous();
    continue nextCand;
    }
    }
    return candidate;
    }
    }
    return -1; // No candidate matched the target }

  • 相关阅读:
    出差兰州
    出差乌鲁木齐(3)
    依赖倒置原则
    .NET 打印界面
    出差乌鲁木齐2
    出差乌鲁木齐(2)
    出差乌鲁木齐3
    IStyleGallery.AddItem、UpdateItem、RemoveItem用法
    Shapefile记录检索
    c#利用最小二乘法拟合任意次函数曲线(转)
  • 原文地址:https://www.cnblogs.com/adolfmc/p/3821736.html
Copyright © 2011-2022 走看看