12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package pathgame.algorithm;
- import java.util.ArrayList;
- /** Class for storing and managing a list of graph vertexes with odd degrees
- *
- */
- public class OddDegreeList {
- private ArrayList<Integer> items = new ArrayList<>();
- private ArrayList<Boolean> itemUsed = new ArrayList<>();
- /** Adds a vertex to the list
- *
- * @param vertex index of the vertex in the list of all vertexes
- */
- public void add(int vertex) {
- items.add(vertex);
- itemUsed.add(false);
- }
- /** Returns the size of the list of vertexes
- *
- * @return the size of the list of vertexes
- */
- public int size() {
- return items.size();
- }
- /** Resets which vertexes have already been used for the permutation
- *
- */
- public void resetUsed() {
- for(int i = 0; i < itemUsed.size(); i++) {
- itemUsed.set(i, false);
- }
- }
- /** Returns the next unused vertex after the given offset
- *
- * @param offSet number of unused vertexes that are skipped before returning a vertex
- * @return the next unused vertex after the offset
- */
- public int getUnused(int offSet) {
- return items.get(getOffsetPos(offSet));
- }
- /** Makes an unused vertex used after the given offset
- *
- * @param offSet number of unused vertexes that are skipped before making the vertex used
- * @return the index of the vertex that was made used
- */
- public int makeOffsetUsed(int offSet) {
- int pos = getOffsetPos(offSet);
- itemUsed.set(pos, true);
- return pos;
- }
- /** makes the vertex at the given position unused
- *
- * @param pos index of the vertex that is made unused
- */
- public void makeUnused(int pos) {
- itemUsed.set(pos, false);
- }
- private int getOffsetPos(int offSet) {
- int foundValid = 0;
- for (int i = 0; i < items.size(); i++) {
- if (!itemUsed.get(i)) {
- if (offSet == foundValid) {
- return i;
- }
- foundValid++;
- }
- }
- return -1;
- }
- }
|