本文整理匯總了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();
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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));
}
}
示例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)));
}
}
示例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));
}
}
}