当前位置: 首页>>代码示例>>Java>>正文


Java TreeSet.pollFirst方法代码示例

本文整理汇总了Java中java.util.TreeSet.pollFirst方法的典型用法代码示例。如果您正苦于以下问题:Java TreeSet.pollFirst方法的具体用法?Java TreeSet.pollFirst怎么用?Java TreeSet.pollFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.TreeSet的用法示例。


在下文中一共展示了TreeSet.pollFirst方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRetainAll

import java.util.TreeSet; //导入方法依赖的package包/类
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    TreeSet q = populatedSet(SIZE);
    TreeSet p = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.pollFirst();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TreeSetTest.java

示例2: main

import java.util.TreeSet; //导入方法依赖的package包/类
public static void main(String ... ags)throws IOException
{
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(in.readLine());
	StringTokenizer tk = new StringTokenizer(in.readLine());
	TreeSet<Integer> ts = new TreeSet<>();
	while(tk.hasMoreTokens())
		ts.add(Integer.parseInt(tk.nextToken()));
	int count = 0;
	while(ts.size()>0)
	{
		int x = ts.first() + 4;
		count++;
		while(ts.size()>0 && ts.first() <= x)
		{
			ts.pollFirst();
		}
	}
	System.out.println(count);
}
 
开发者ID:hell-sing,项目名称:hacker-rank,代码行数:21,代码来源:Priyanka_and_toys.java

示例3: main

import java.util.TreeSet; //导入方法依赖的package包/类
public static void main(String ... ags)throws IOException
{
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	int n = Integer.parseInt(in.readLine());
	StringTokenizer tk = new StringTokenizer(in.readLine());
	TreeSet<Integer> ts = new TreeSet<>();
	for(int i=0;i<n;i++)
	{
		int val = Integer.parseInt(tk.nextToken());
		if(val%2 != 0)
			ts.add(i);
	}
	if(ts.size()%2 != 0)
		System.out.println("NO");
	else
	{
		int res = 0;
		while(ts.size() != 0)
		{
			int a = ts.pollFirst();
			int b = ts.pollFirst();
			res += (b-a-1)*2 + 2;
		}
		System.out.println(res);
	}
}
 
开发者ID:hell-sing,项目名称:hacker-rank,代码行数:27,代码来源:Fair_Rations.java

示例4: applyTextRecovery

import java.util.TreeSet; //导入方法依赖的package包/类
/**
 * Applies text recovery to the gray image. See section IV.B
 * @param map The gray image after global thresholding.
 * @param postLocalThresholdMap The gray image after local thresholding.
 * @return The gray image after text recovery.
 */
public static GrayImage applyTextRecovery(GrayImage map,
	GrayImage postLocalThresholdMap) {

	GrayImage res = textLabeling(map, postLocalThresholdMap);
	TreeSet<Pixel> newTextPixels = new TreeSet<>();

	for (int j = 0; j < map.getHeight(); ++j) {
		for (int i = 0; i < map.getWidth(); ++i) {
			newTextPixels.clear();
			if (res.getValue(i, j) > 0) {
				int x = i, y = j;
				do {
					if (!newTextPixels.isEmpty()) {
						Point p = newTextPixels.pollFirst();
						x = (int) p.getX();
						y = (int) p.getY();
					}
					applyHysteresisMask(map, res, x, y, newTextPixels);
				} while (!newTextPixels.isEmpty());
			}
		}
	}

	return res;
}
 
开发者ID:MX-Futhark,项目名称:text-position-detector,代码行数:32,代码来源:EdgeMap.java

示例5: createTestData

import java.util.TreeSet; //导入方法依赖的package包/类
/**
 * Create the test data with given parameters.
 *
 * @param p_totalItemCount
 *         Max number of items for the test data.
 * @param p_randDistFillRate
 *         Distribution/Fill rate for the test data.
 * @return Array with shuffled test data.
 */
private long[] createTestData(final int p_totalItemCount, final float p_randDistFillRate) {
    long[] testData;
    if (p_randDistFillRate < 1.0f && p_randDistFillRate > 0.0f) {
        System.out.println("Creating random distribution test data...");

        Random rand = new Random();
        TreeSet<Long> set = new TreeSet<>();
        testData = new long[(int) (p_totalItemCount * p_randDistFillRate)];
        int setCount = 0;

        // use a set to ensure generating non duplicates until we hit the specified fill rate
        while (((float) setCount / p_totalItemCount) < p_randDistFillRate) {
            if (set.add((long) (rand.nextFloat() * p_totalItemCount))) {
                setCount++;
            }
        }

        for (int i = 0; i < testData.length; i++) {
            testData[i] = set.pollFirst();
        }
        shuffleArray(testData);
    } else {
        System.out.println("Creating continous test data...");

        testData = new long[p_totalItemCount];
        for (int i = 0; i < testData.length; i++) {
            testData[i] = i;
        }
    }
    return testData;
}
 
开发者ID:hhu-bsinfo,项目名称:dxram,代码行数:41,代码来源:BFSFrontierBenchmarks.java

示例6: find

import java.util.TreeSet; //导入方法依赖的package包/类
@Override
public Collection<? extends Point> find(Point from, Point destination, DistanceComparator distanceComparator,
		CollisionDetector collisionDetector)
{
	Map<Point, Point> parents = new HashMap<>();
	TreeSet<Point> openList = new TreeSet<>(distanceComparator);
	HashSet<Point> closedList = new HashSet<>();
	openList.add(from);
	Point n = null; 
	Point closestNode = from;
	while (!openList.isEmpty())
	{
		n = openList.pollFirst();

		if(distanceComparator.compare(closestNode, n) > 0)
			closestNode = n;
		if (n.equals(destination))
			return createPath(from, destination, parents);
		
		closedList.add(n);
		List<Point> successors = createSuccessors(n, collisionDetector);
		for (Point successor: successors)
		{
			if (!closedList.contains(successor))
			{
				openList.add(successor);
				if (!parents.containsKey(successor)) 
					parents.put(successor, n);
			}
		}
	}

	return createPath(from, closestNode, parents);
}
 
开发者ID:MMORPG-Prototype,项目名称:MMORPG_Prototype,代码行数:35,代码来源:BestFirstPathFinder.java

示例7: testEmpty

import java.util.TreeSet; //导入方法依赖的package包/类
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    TreeSet q = new TreeSet();
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.pollFirst();
    q.pollFirst();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:TreeSetTest.java

示例8: testSize

import java.util.TreeSet; //导入方法依赖的package包/类
/**
 * size changes when elements added and removed
 */
public void testSize() {
    TreeSet q = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(SIZE - i, q.size());
        q.pollFirst();
    }
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.size());
        q.add(new Integer(i));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:TreeSetTest.java

示例9: testContains

import java.util.TreeSet; //导入方法依赖的package包/类
/**
 * contains(x) reports true when elements added but not yet removed
 */
public void testContains() {
    TreeSet q = populatedSet(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertTrue(q.contains(new Integer(i)));
        q.pollFirst();
        assertFalse(q.contains(new Integer(i)));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:TreeSetTest.java

示例10: testRemoveAll

import java.util.TreeSet; //导入方法依赖的package包/类
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        TreeSet q = populatedSet(SIZE);
        TreeSet p = populatedSet(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.pollFirst());
            assertFalse(q.contains(x));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:TreeSetTest.java


注:本文中的java.util.TreeSet.pollFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。