Package edu.princeton.cs.algs4
Class CollisionSystem
- Object
-
- edu.princeton.cs.algs4.CollisionSystem
-
public class CollisionSystem extends Object
TheCollisionSystem
class represents a collection of particles moving in the unit box, according to the laws of elastic collision. This event-based simulation relies on a priority queue.For additional documentation, see Section 6.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
- Author:
- Robert Sedgewick, Kevin Wayne
-
-
Constructor Summary
Constructors Constructor Description CollisionSystem(Particle[] particles)
Initializes a system with the specified collection of particles.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
main(String[] args)
Unit tests theCollisionSystem
data type.void
simulate(double limit)
Simulates the system of particles for the specified amount of time.
-
-
-
Constructor Detail
-
CollisionSystem
public CollisionSystem(Particle[] particles)
Initializes a system with the specified collection of particles. The individual particles will be mutated during the simulation.- Parameters:
particles
- the array of particles
-
-
Method Detail
-
simulate
public void simulate(double limit)
Simulates the system of particles for the specified amount of time.- Parameters:
limit
- the amount of time
-
main
public static void main(String[] args)
Unit tests theCollisionSystem
data type. Reads in the particle collision system from a standard input (or generatesN
random particles if a command-line integer is specified); simulates the system.- Parameters:
args
- the command-line arguments
-
-