Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class Node
- {
- public PrimeFactor pFactor; // prime factor
- public Node next;
- public Node previous;
- /**
- * Default constructor for creating a dummy node.
- */
- public Node()
- {
- }
- /**
- * Precondition: p is a prime
- *
- * @param p prime number
- * @param m multiplicity
- * @throws IllegalArgumentException if m < 1
- */
- public Node(int p, int m) throws IllegalArgumentException
- {
- if(m < 1) {
- throw new IllegalArgumentException();
- }
- pFactor = new PrimeFactor(p,m);
- }
- /**
- * Constructs a node over a provided PrimeFactor object.
- *
- * @param pf
- * @throws IllegalArgumentException
- */
- public Node(PrimeFactor pf)
- {
- pFactor = new PrimeFactor(pf.prime, pf.multiplicity);
- }
- /**
- * Printed out in the form: prime + "^" + multiplicity. For instance "2^3".
- * Also, deal with the case pFactor == null in which a string "dummy" is
- * returned instead.
- */
- @Override
- public String toString()
- {
- String X = "";
- if(pFactor == null) {
- X = "dummy";
- }
- else{
- if(pFactor.multiplicity == 1) {
- X = pFactor.prime + "";
- }
- else {
- X = pFactor.prime + "^" + pFactor.multiplicity;
- }
- }
- return X;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement