use of edu.princeton.cs.algs4.MinPQ in project AlgorithmsSolutions by Allenskoo856.
the class TopM method main.
public static void main(String[] args) {
int M = Integer.parseInt(args[0]);
MinPQ<Transaction> pq = new MinPQ<Transaction>(M + 1);
while (StdIn.hasNextLine()) {
pq.insert(new Transaction(StdIn.readLine()));
if (pq.size() > M) {
pq.delMin();
}
}
Stack<Transaction> stack = new Stack<Transaction>();
while (!pq.isEmpty()) {
stack.push(pq.delMin());
}
for (Transaction t : stack) {
StdOut.println(t);
}
}
use of edu.princeton.cs.algs4.MinPQ in project AlgorithmsSolutions by Allenskoo856.
the class CollisionSystem method simulate.
public void simulate(double limit, double Hz) {
pq = new MinPQ<Event>();
for (int i = 0; i < particles.length; i++) {
predictCollisions(particles[i], limit);
}
pq.insert(new Event(0, null, null));
while (!pq.isEmpty()) {
Event event = pq.delMin();
if (!event.isValid()) {
continue;
}
for (int i = 0; i < particles.length; i++) {
particles[i].move(event.time - t);
}
t = event.time;
Particle a = event.a, b = event.b;
if (a != null && b != null) {
a.bounceOff(b);
} else if (a != null && b == null) {
a.bounceOffVerticalWall();
} else if (a == null && b != null) {
b.bounceOffHorizontalWall();
} else if (a == null && b == null) {
redraw(limit, Hz);
}
predictCollisions(a, limit);
predictCollisions(b, limit);
}
}
Aggregations