Ejemplo n.º 1
0
  public void paint(Graphics g) {
    // clear field
    super.paint(g);

    // draw grid lines
    g.setColor(Color.DARK_GRAY);
    gridXIter = gridX.listIterator();
    while (gridXIter.hasNext()) {
      int x = gridXIter.next();
      g.drawLine(x, 0, x, getHeight());
    }
    gridYIter = gridY.listIterator();
    while (gridYIter.hasNext()) {
      int y = gridYIter.next();
      g.drawLine(0, y, getWidth(), y);
    }

    // draw objects
    ListIterator<PhysicsObject> iter = Universe.allObjects.listIterator();
    while (iter.hasNext()) {
      PhysicsObject obj = iter.next();
      int x = (int) (obj.getX() * pixelsPerMeter + origin.x);
      int y = (int) (obj.getY() * pixelsPerMeter + origin.y);
      g.fillOval(x - 5, y - 5, 10, 10); // TODO update for non-point objects
    }
  }
Ejemplo n.º 2
0
  /**
   * Sends the data from the vectors to the X and Y array.
   *
   * @see #getXData()
   * @see #getYData()
   */
  private void sendDataToDoubleArray() {
    xDoubleData = new double[xData.size()];

    ListIterator iterator = xData.listIterator();
    Double next = null;
    int counter = 0;

    while (iterator.hasNext()) {
      next = (Double) iterator.next();
      xDoubleData[counter] = next.doubleValue();
      counter++;
    }

    yDoubleData = new double[yData.size()];
    iterator = yData.listIterator();
    counter = 0;

    while (iterator.hasNext()) {
      next = (Double) iterator.next();
      yDoubleData[counter] = next.doubleValue();
      counter++;
    }

    xData = yData = null;
  }
Ejemplo n.º 3
0
 void computeIn(LinkedList<Vertex> worklist) {
   int i;
   BitSet old;
   BitSet ne;
   Vertex v;
   ListIterator<Vertex> iter;
   iter = succ.listIterator();
   while (iter.hasNext()) {
     v = iter.next();
     out.or(v.in);
   }
   old = in;
   in = new BitSet();
   in.or(out);
   in.andNot(def);
   in.or(use);
   if (!in.equals(old)) {
     iter = pred.listIterator();
     while (iter.hasNext()) {
       v = iter.next();
       if (!v.listed) {
         worklist.addLast(v);
         v.listed = true;
       }
     }
   }
 }
  /**
   * Either adds a value to set or does nothing if value is already present.
   *
   * @param val Value to add.
   * @return The instance of value from this set or {@code null} if value was added.
   */
  @Nullable
  public V addx(V val) {
    A.notNull(val, "val");

    if (comp == null) {
      for (V v : vals) if (v.equals(val)) return v;

      vals.add(val);

      return null;
    }

    if (strict) {
      for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) {
        V v = it.next();

        // Prefer equals to comparator.
        if (v.equals(val)) return v;

        int c = comp.compare(v, val);

        if (c == 0) throw new IllegalStateException("Inconsistent equals and compare methods.");

        if (c > 0) {
          // Back up.
          it.previous();

          it.add(val);

          return null;
        }
      }

      vals.add(val);

      return null;
    }

    // Full scan first.
    for (V v : vals) if (v.equals(val)) return v;

    for (ListIterator<V> it = vals.listIterator(); it.hasNext(); ) {
      V v = it.next();

      if (comp.compare(v, val) > 0) {
        do {
          // Back up.
          v = it.previous();
        } while (comp.compare(v, val) == 0);

        it.add(val);

        return null;
      }
    }

    vals.add(val);

    return null;
  }
Ejemplo n.º 5
0
 public String toString() {
   String str = "PDepNetwork #" + Integer.toString(id) + ":\n";
   str += "\tIsomers:\n";
   for (ListIterator<PDepIsomer> iter = isomerList.listIterator(); iter.hasNext(); ) {
     PDepIsomer isomer = iter.next();
     str += "\t\t" + isomer.toString() + "\n";
   }
   str += "\tPath reactions:\n";
   for (ListIterator<PDepReaction> iter = pathReactionList.listIterator(); iter.hasNext(); ) {
     PDepReaction rxn = iter.next();
     str += "\t\t" + rxn.toString() + "\n";
   }
   str += "\tNet reactions:\n";
   for (ListIterator<PDepReaction> iter = netReactionList.listIterator(); iter.hasNext(); ) {
     PDepReaction rxn = iter.next();
     str += "\t\t" + rxn.toString() + "\n";
   }
   str += "\tNonincluded reactions:\n";
   for (ListIterator<PDepReaction> iter = nonincludedReactionList.listIterator();
       iter.hasNext(); ) {
     PDepReaction rxn = iter.next();
     str += "\t\t" + rxn.toString() + "\n";
   }
   return str;
 }
Ejemplo n.º 6
0
 public static void repeat(LinkedList<String> x) {
   ListIterator<String> iter = x.listIterator();
   while (iter.hasNext()) {
     System.out.print(iter.next());
   }
   // print
   iter = x.listIterator();
   while (iter.hasNext()) {
     System.out.print(iter.next());
   }
 }
Ejemplo n.º 7
0
  /**
   * *************************************************************** @Description - The default
   * constructor for the command line text editor. This configures and sets up the linked list for
   * the editor. @Returns - (N/A)
   *
   * <p>**************************************************************
   */
  public Editor() {

    // Build the linked list.
    textData = new LinkedList<String>();
    CurrentLine = textData.listIterator();

    // Build the clip board.
    clipBoard = new LinkedList<String>();
    clipBoardLine = clipBoard.listIterator();

    // Configure the file editor.
    documentLineCount = 0;
  }
Ejemplo n.º 8
0
  public static void delete(LinkedList<String> x, String searchFor) {
    ListIterator<String> iter = x.listIterator();
    while (iter.hasNext()) {
      if (iter.next().equals(searchFor)) {
        iter.remove();
      }
    }

    // print
    iter = x.listIterator();
    while (iter.hasNext()) {
      System.out.print(iter.next());
    }
  }
Ejemplo n.º 9
0
  public LinkedList<MapLocation> pathFind(MapLocation start, MapLocation target)
      throws GameActionException {
    //		for (int i = 0; i < myRobot.allies.length; i++) {
    //			RobotInfo r = rc.senseRobotInfo(myRobot.allies[i]);
    //			if (myRobot.allies[i].getID() == myRobot.ID) continue;
    //			map[r.location.x][r.location.y] = -2;
    //		}
    //		for (int i = 0; i < myRobot.enemies.length; i++) {
    //			RobotInfo r = rc.senseRobotInfo(myRobot.enemies[i]);
    //			map[r.location.x][r.location.y] = -2;
    //		}
    int x = Clock.getRoundNum();
    SearchNode bugSearch = bugSearch(start, target);
    SearchNode[] nodes = new SearchNode[bugSearch.length];
    int counter = bugSearch.length - 1;
    while (bugSearch.prevLoc != null) {
      nodes[counter] = bugSearch;
      bugSearch = bugSearch.prevLoc;
      counter--;
    }

    nodes[0] = bugSearch;
    LinkedList<MapLocation> pivots = new LinkedList<MapLocation>();
    pivots.add(nodes[0].loc);

    for (int i = 1; i < nodes.length; i++) {
      if (nodes[i].isPivot) {
        pivots.add(nodes[i].loc);
      }
    }

    counter = 0;
    ListIterator<MapLocation> li1 = pivots.listIterator(), li2;
    while (li1.hasNext()) {
      li2 = pivots.listIterator(pivots.size());
      while (li2.hasPrevious() && li2.previousIndex() > li1.nextIndex() + 1) {
        if (canTravel(li1.next(), li2.previous())) {
          pivots.subList(li1.nextIndex(), li2.previousIndex() + 1).clear();
          li1 = pivots.listIterator(++counter);
          break;
        }
        li1.previous();
      }
      li1.next();
    }

    if (false) System.out.println(Clock.getRoundNum() - x);
    return pivots;
  }
Ejemplo n.º 10
0
  public synchronized void act() {
    g = AsteroidsFrame.getGBuff();
    ListIterator<Misile> iter = theMisiles.listIterator();
    while (iter.hasNext()) {
      Misile m = iter.next();
      if (m.needsRemoval()) iter.remove();
      else m.act(g);
    }

    iter = toBeAdded.listIterator();
    while (iter.hasNext()) {
      theMisiles.add(iter.next());
      iter.remove();
    }
  }
 private void relabelToFront() {
   assert (!V.isEmpty()) : "No vertices";
   ListIterator<Vertex> iter = V.listIterator();
   while (iter.hasNext()) {
     Vertex v = iter.next();
     // System.out.println("Considering vertex: " + v);
     int oldHeight = v.getHeight();
     discharge(v);
     if (v.getHeight() > oldHeight) {
       iter.remove();
       V.addFirst(v);
       iter = V.listIterator(1);
     }
   }
 }
Ejemplo n.º 12
0
  private List<ChatMessage> sanitizeMap(final SortedMap<Date, ChatMessage> aMap) {
    if (aMap.isEmpty() || aMap.size() == 1) return Lists.newArrayList(aMap.values());

    final LinkedList<ChatMessage> ret = Lists.newLinkedList(aMap.values());
    final ListIterator<ChatMessage> i = ret.listIterator();
    ChatMessage prevMsg = i.next();
    do {
      ChatMessage msg = i.next();
      if (!msg.getPreviousMessageDate().equals(prevMsg.getDate())) {
        if (msg.getPreviousMessageDate().before(prevMsg.getDate())) {
          msg.setPreviousMessageDate(prevMsg.getDate());
        } else {
          final ChatMessage tmp =
              createLostMessageBetween(
                  msg.getRoom(), prevMsg.getDate(), msg.getPreviousMessageDate());
          aMap.put(tmp.getDate(), tmp);
          i.previous();
          i.add(tmp);
          i.next();
          msg = tmp;
        }
      }
      prevMsg = msg;
    } while (i.hasNext());

    return ret;
  }
 protected void makeSpines(LinkedList<StackSorterTriple> triples) {
   System.out.println("makeSpines");
   spines = new LinkedList<SpineRepresentation>();
   ListIterator<StackSorterTriple> li = triples.listIterator();
   while (li.hasNext()) {
     StackSorterTriple triple = li.next();
     Hashtable<String, Serializable> hash = triple.getItemInfo();
     if (hash != null) {
       String itemS = (String) hash.get("item");
       if (itemS != null) {
         Integer itemAkt = Integer.parseInt(itemS);
         boolean isSpecial = itemAkt.equals(item);
         System.out.println(itemAkt);
         // SpineRepresentationImpl spine=new
         // SpineRepresentationImpl(new
         // BibliographicStatusSorterImpl(itemAkt,(String)hash.get("ibarcode"),(String)hash.get("status"),(String)hash.get("collection")),isSpecial,false);
         SpineRepresentationImpl spine =
             new SpineRepresentationImpl(
                 new BibliographicStatusSorterImpl(
                     Integer.parseInt((String) hash.get("bib")),
                     (String) hash.get("ibarcode"),
                     (String) hash.get("status"),
                     (String) hash.get("collection")),
                 isSpecial,
                 false);
         spines.add(spine);
       } else {
         System.out.println("SpineGetterSorterImp.makeSpines: item null.");
       }
     } else {
       System.out.println("SpineGetterSorterImp.makeSpines: hash null.");
     }
   }
 }
Ejemplo n.º 14
0
  public static void maxFlow(ListGraph g) {
    ListGraph residualG = g.residualGraph();

    LinkedList<DirEdge> path = residualG.getFlowPath();
    while (path != null) {
      // System.out.println("Got path");
      int minCapacity = ListGraph.minCapacityInPath(path);

      assert minCapacity > 0;
      // augment every edge on the path in the original graph
      int head = g.getSource();
      ListIterator it = path.listIterator();
      while (it.hasNext()) {
        DirEdge rEdge = (DirEdge) it.next();
        int tail = rEdge.end;

        DirEdge e = g.getEdge(head, tail);
        e.flow += minCapacity;

        // System.out.println("Augmenting (" + head + "," + tail + ") to be " + e.flow);

        head = tail;
      }

      residualG = g.residualGraph();

      // System.out.println("g:");
      // g.print();

      // System.out.println("Residual graph:");
      // residualG.print();

      path = residualG.getFlowPath();
    }
  }
Ejemplo n.º 15
0
  /** returns a HTML string representation the neighboor list */
  public String toHTML() {
    String trust = "<FONT size=+1 color=green>TRUSTED</FONT>";
    if (!this.isConfident()) trust = "<FONT size=+1 color=red>DISTRUSTED</FONT>";

    String res =
        "<B>Neighboor list</B> (" + neighboorList.size() + "neighboors / " + trust + ")<BR>";

    res += "<TABLE border=1>";
    res += "<TR><TD>id</TD><TD>trust</TD><TD>role</TD><TD>group</TD></TR>";
    TrustedTripletIdRoleGroup triplet;
    ListIterator<TrustedTripletIdRoleGroup> iter = neighboorList.listIterator();
    while (iter.hasNext()) {
      triplet = iter.next();
      res +=
          "<TR><TD>"
              + triplet.id
              + "</TD><TD>"
              + triplet.trust
              + "</TD><TD>"
              + TrustedMWACAgent.roleToString(triplet.role)
              + "</TD><TD>"
              + MWACGroupAssistant.groupsToString(triplet.groups)
              + "</TD></TR>";
    }
    res += "</TABLE>";
    return res;
  }
  @Override
  public boolean incrementToken() throws IOException {
    while (!done && queue.size() < windowSize) {
      if (!input.incrementToken()) {
        done = true;
        break;
      }

      // reverse iterating for better efficiency since we know the
      // list is already sorted, and most token start offsets will be too.
      ListIterator<OrderedToken> iter = queue.listIterator(queue.size());
      while (iter.hasPrevious()) {
        if (offsetAtt.startOffset() >= iter.previous().startOffset) {
          // insertion will be before what next() would return (what
          // we just compared against), so move back one so the insertion
          // will be after.
          iter.next();
          break;
        }
      }
      OrderedToken ot = new OrderedToken();
      ot.state = captureState();
      ot.startOffset = offsetAtt.startOffset();
      iter.add(ot);
    }

    if (queue.isEmpty()) {
      return false;
    } else {
      restoreState(queue.removeFirst().state);
      return true;
    }
  }
  /**
   * Caches the path that was just found.
   *
   * @param smiod
   * @param endNode
   * @param startNode
   */
  private void cachePath(StreetMobilityInfoOD smiod, SegmentNode startNode, SegmentNode endNode) {
    if (hm != null && smiod.path.size() > MIN_CACHED_PATH_LENGTH) {
      Location startPoint = startNode.point;

      LinkedList ll = (LinkedList) hm.get(startPoint);
      if (ll == null) {
        ll = new LinkedList();
      }
      // make sure that path doesn't already exist...
      // must iterate through all of them...
      ListIterator li = ll.listIterator();
      boolean found = false;
      while (li.hasNext()) {
        LinkedList existingPath = (LinkedList) li.next();
        if (existingPath.getFirst().equals(startNode)
            && existingPath.getLast().equals(smiod.path.getLast())) {
          found = true;
          break;
        }
      }
      if (!found) {
        LinkedList newPath = (LinkedList) smiod.path.clone();
        newPath.addFirst(startNode);
        ll.add(newPath);
        hm.put(startPoint, ll);
      }
    }
  }
Ejemplo n.º 18
0
  /**
   * Generate string of evaluated tokens of parameters of the agent.
   *
   * @param agent whether the parameters belong to.
   * @return string of evaluated parameters.
   */
  private String _agentParameterTokens(NamedObj agent) throws IllegalActionException {
    LinkedList parameterList = (LinkedList) agent.attributeList(Parameter.class);
    ListIterator parameters = parameterList.listIterator();

    String tokenString = "";

    while (parameters.hasNext()) {
      Parameter parameter = (Parameter) parameters.next();
      String parameterName = parameter.getName();

      if (parameterName.startsWith("_")) {
        continue;
      }

      String tokenValue = parameter.getToken().toString();

      if (tokenString == "") {
        tokenString += tokenValue;
      } else {
        tokenString += (", " + tokenValue);
      }
    }

    return tokenString;
  }
Ejemplo n.º 19
0
  /**
   * Generate string of parameters of the agent.
   *
   * @param agent whether the parameters belong to.
   * @param typed indicates whether the parameters have type.
   * @return string of parameters.
   */
  private String _agentParameters(NamedObj agent, boolean typed) {
    LinkedList parameterList = (LinkedList) agent.attributeList(Parameter.class);
    ListIterator parameters = parameterList.listIterator();

    String prefix = "";

    if (typed) {
      prefix = "real ";
    }

    String parameterString = "";

    while (parameters.hasNext()) {
      String parameterName = ((NamedObj) parameters.next()).getName();

      if (parameterName.startsWith("_")) {
        continue;
      }

      if (parameterString == "") {
        parameterString += (prefix + parameterName);
      } else {
        parameterString += (", " + prefix + parameterName);
      }
    }

    return parameterString;
  }
Ejemplo n.º 20
0
  /**
   * Calculates the isomer with the largest leak flux for this network. The reaction with the
   * maximum flux is used to select the isomer. This isomer is the candidate for elevating to
   * included status.
   *
   * @param ss A system snapshot (T, P, concentrations, etc.) to use to calculate the flux.
   * @return The isomer with the largest leak flux
   */
  public PDepIsomer getMaxLeakIsomer(SystemSnapshot ss) throws PDepException {

    if (nonincludedReactionList.size() == 0)
      throw new PDepException(
          "Tried to determine nonincluded isomer with maximum leak flux, but there are no nonincluded reactions, so no isomer can be identified.");

    PDepReaction maxReaction = null;
    double maxLeak = 0.0;
    for (ListIterator<PDepReaction> iter = nonincludedReactionList.listIterator();
        iter.hasNext(); ) {
      PDepReaction rxn = iter.next();
      if (!rxn.getReactant().getIncluded() || !rxn.getProduct().getIncluded()) {
        if (Math.abs(rxn.calculateFlux(ss)) > maxLeak) {
          maxReaction = rxn;
          maxLeak = rxn.calculateFlux(ss);
        }
      }
    }

    if (!maxReaction.getReactant().getIncluded()) return maxReaction.getReactant();
    else if (!maxReaction.getProduct().getIncluded()) return maxReaction.getProduct();
    else
      throw new PDepException(
          "Tried to determine nonincluded isomer with maximum leak flux, but nonincluded reaction with maximum leak flux has no nonincluded isomers.");
  }
Ejemplo n.º 21
0
  /**
   * returns writer index.
   *
   * @param cb of type channel buffer
   * @return length of bytes written to channel buffer
   */
  protected int packOptionalTlv(ChannelBuffer cb) {

    ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator();
    int startIndex = cb.writerIndex();

    while (listIterator.hasNext()) {
      PcepValueType tlv = listIterator.next();

      if (tlv == null) {
        log.debug("tlv is null from OptionalTlv list");
        continue;
      }

      tlv.write(cb);

      // need to take care of padding
      int pad = tlv.getLength() % 4;

      if (0 != pad) {
        pad = 4 - pad;
        for (int i = 0; i < pad; ++i) {
          cb.writeByte((byte) 0);
        }
      }
    }

    return cb.writerIndex() - startIndex;
  }
Ejemplo n.º 22
0
 public static void main(String args[]) {
   ArrayList<Integer> numList = new ArrayList<Integer>();
   for (int i = 1; i <= 5; i++) {
     numList.add(i);
   }
   System.out.println("Size of Array List is " + numList.size());
   System.out.println("List elements");
   ListIterator<Integer> li = numList.listIterator();
   for (; li.hasNext(); ) {
     Integer num = li.next();
     System.out.println(num);
   }
   System.out.println("List elements in reverse");
   for (; li.hasPrevious(); ) {
     Integer num = li.previous();
     System.out.println(num);
   }
   LinkedList<String> strList = new LinkedList<String>();
   strList.add("abc");
   strList.add("def");
   strList.add("abc");
   strList.add("ghi");
   System.out.println("Index of abc is: " + strList.indexOf("abc"));
   System.out.println("Size of Linked List is " + strList.size());
   strList.remove("abc");
   for (ListIterator<String> ls = strList.listIterator(); ls.hasNext(); ) {
     String str = ls.next();
     System.out.println(str);
   }
 }
Ejemplo n.º 23
0
 public boolean contains(String word) {
   ListIterator<CrosswordEntry> it = entries.listIterator();
   while (it.hasNext()) {
     if (it.next().getWord().equals(word)) return true;
   }
   return false;
 }
  public void updateRound() {
    ListIterator<Action> actionIterator = actions.listIterator();
    while (actionIterator.hasNext()) {
      Action a = actionIterator.next();
      if (currentRound >= (a.roundStarted + a.length)) {
        actionIterator.remove();
      }
    }

    aliveRounds += 1;

    updateDrawLoc();

    broadcast = (broadcast << 1) & 0x000FFFFF;
    if (regen > 0) regen--;

    Iterator<Map.Entry<Animation.AnimationType, Animation>> it = animations.entrySet().iterator();
    Map.Entry<Animation.AnimationType, Animation> entry;
    while (it.hasNext()) {
      entry = it.next();
      entry.getValue().updateRound();
      if (!entry.getValue().isAlive()) {
        if (entry.getKey() != DEATH_EXPLOSION) it.remove();
      }
    }
    currentRound++;
  }
Ejemplo n.º 25
0
  void tryToDeleteSegment(Point p) {
    if (points.size() < 3) return;

    LatLon start;
    start = findBigSegment(p);
    ListIterator<LatLon> it = points.listIterator();
    LatLon pp;
    boolean f = false;
    int i = 0, idx = -1;
    while (it.hasNext()) {
      pp = it.next();
      if (f && (fixed.contains(pp))) {
        // if end of line fragment reached
        lastIdx = idx;
        return;
      }
      if (f && (!it.hasNext())) {
        // if end of whole line reached
        closedFlag = false;
        it.remove();
        lastIdx = points.size() - 1;
        return;
      }

      // if we are deleting this segment
      if (f) it.remove();
      if (pp == start) {
        f = true;
        idx = i;
      } // next node should be removed
      i++;
    }
    lastIdx = points.size() - 1;
  }
Ejemplo n.º 26
0
  /** Checks all the servers marked as being online if they still are online. */
  private synchronized void checkOnlineServers() {
    Iterator itr;
    itr = online.listIterator();
    while (itr.hasNext()) {
      Server server = (Server) itr.next();
      String url = getServerURL(server);
      GetMethod get = new GetMethod(url);
      get.setFollowRedirects(false);

      try {
        httpClient.executeMethod(get);
        if (!okServerResponse(get.getStatusCode())) {
          offline.add(server);
          itr.remove();
          log.debug("Server going OFFLINE! " + getServerURL(server));
          listener.serverOffline(server);
        }
      } catch (Exception e) {
        offline.add(server);
        itr.remove();
        log.debug("Server going OFFLINE! " + getServerURL(server));
        listener.serverOffline(server);
      } finally {
        get.releaseConnection();
      }
    }
  }
Ejemplo n.º 27
0
 /**
  * Checks to see if the network contains species as a unimolecular isomer.
  *
  * @param species The species to check for
  * @return True if species is a unimolecular isomer in the network, false if not
  */
 public boolean contains(Species species) {
   for (ListIterator<PDepIsomer> iter = isomerList.listIterator(); iter.hasNext(); ) {
     PDepIsomer isomer = iter.next();
     if (isomer.getSpecies(0).equals(species) && isomer.isUnimolecular()) return true;
   }
   return false;
 }
Ejemplo n.º 28
0
    public String hasSameContent(JarFile2 file, JarEntry entry) throws IOException {

      String thisName = null;

      Long crcL = new Long(entry.getCrc());

      // check if this jar contains files with the passed in entry's crc
      if (_crcToEntryMap.containsKey(crcL)) {
        // get the Linked List with files with the crc
        LinkedList ll = (LinkedList) _crcToEntryMap.get(crcL);
        // go through the list and check for content match
        ListIterator li = ll.listIterator(0);
        if (li != null) {
          while (li.hasNext()) {
            JarEntry thisEntry = (JarEntry) li.next();

            // check for content match
            InputStream oldIS = getJarFile().getInputStream(thisEntry);
            InputStream newIS = file.getJarFile().getInputStream(entry);

            if (!differs(oldIS, newIS)) {
              thisName = thisEntry.getName();
              return thisName;
            }
          }
        }
      }

      return thisName;
    }
  public static void main(String[] args) throws IOException {
    BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));

    ArrayList<ArrayList<Pair>> G;

    int T = Integer.parseInt(inp.readLine());
    int startVertex = 0;
    int graphSize = 50;
    for (int test = 0; test < T; ++test) {
      int numberOfEdges = Integer.parseInt(inp.readLine());
      G = new ArrayList<ArrayList<Pair>>();
      for (int index = 0; index < graphSize; ++index) G.add(new ArrayList<Pair>());
      for (int edge = 0; edge < numberOfEdges; ++edge) {
        String[] tokens = inp.readLine().split("\\s");
        int u = Integer.parseInt(tokens[0]);
        --u;
        int v = Integer.parseInt(tokens[1]);
        --v;
        startVertex = u;
        G.get(u).add(new Pair(v, 1));
        G.get(v).add(new Pair(u, 1));
      }
      System.out.println("Case #" + (test + 1));
      if (isEulerian(G)) {
        LinkedList<Integer> path = new LinkedList<Integer>();
        eulerPath(G, path.listIterator(), startVertex);
        for (int index = 0; index < path.size() - 1; ++index)
          System.out.println((path.get(index) + 1) + " " + (path.get(index + 1) + 1));
        if (path.size() > 0)
          System.out.println((path.get(path.size() - 1) + 1) + " " + (path.get(0) + 1));
      } else System.out.println("some beads may be lost");
      if (test != T - 1) System.out.println();
    }
  }
Ejemplo n.º 30
-7
  public void addIndividualSorted(TimeTable tt) {
    ListIterator<TimeTable> it = individuals.listIterator();
    ListIterator<TimeTable> it2 = individuals.listIterator();

    while (it.hasNext()) {
      if (it.next().getFitness() < tt.getFitness()) {
        it2.add(tt);
        break;
      }

      it2.next();
    }
  }