With yours, if you don't pop the queue, and keep using front() it'll be the same thing repeatedly. Also if you use Size() in the for loop and pop, you will be counting up and lowering the count so...
Type: Posts; User: Zula
With yours, if you don't pop the queue, and keep using front() it'll be the same thing repeatedly. Also if you use Size() in the for loop and pop, you will be counting up and lowering the count so...
will print the front item in the queue repeatedly without changing it.
as the last part of the for loop means it WILL be in the from but the if empty works fine just pointless
There is one problem, the for loops that use MyQueue.Size() and pop() together are cut short as pop reduces size, make a variable to remember the original size before you start the loop...as such:
...
In that example what happens between "After Iteration 1" when the from queue is empty and "Iteration 2" where it has data...you must transfer it...
There appears to be a problem with your MyQueue or DoublyLinkedList classes...the to queue is not growing properly. my mistake not true..same poping reducing size problem
Hmm...well, you need to empty from as you go through it or it will build up, but I see that doing so changes Size() and makes me run out faster than I should.
Problem though, the final sequence from the generator-koch.txt file has spaces for some reason...so an error in the code somewheres
make it str = console.nextLine().trim(); in the penguin loop
...
// this class takes in productions and generates turtle commands.
import java.util.ArrayList;
import java.io.*;
import java.util.*;
public class program6_part_3
{ // beginning of class...
I misspoke, it ends in the "from" queue, so print from the "from" queue
No offense but your teacher's outline is a bit weird, steps 1&2 are on a different scope than 3,4,5&6, 4,5&6 should have been under 3 and it should have been worded different....but anway, okay, the...
for (int iter =0; iter < numberOfIterations; iter++)
{ // beginning of for
for (int iter2 = 0; iter2 < from.Size(); iter2++)
{ // beginning of for
if(leftSide.contains(from.front()))
{ //...
Make a for loop that goes to.length iterations and pop them from the 'to' queue into the 'from' queue
for(int asdf = 0;asdf<to.length();asdf++) {
from.push(to.front());
to.pop();
}
For the generator-koch.txt file, I get
F-F++F-F++F-F++F-F++F-F++F-FF-F++F-F++F-F++F-F++F-F++F-FF-F++F-F++F-F++F-F++F-F++F-FF-F++F-F++F-F++F-F++F-F++F-FF-F++F-F++F-F++F-F++F-F++F-F
as the...
It appears it would yes.
But what you need to do is in the for loop, once you read in a production, stick it in two queues, one for the lhs(from) and one for the rhs(to)
static Scanner in;
public static void main(String[] args) throws IOException {
in = new Scanner(new File("generator-koch.txt"));
for(int i = 0;i<6;i++) {
...
He means make a queue of all the chars in the starting sequence, then for each char, check if it is a lhs(left hand side) symbol, if so, take the corresponding rhs and substitute the symbol
With scanner.next() it gives you what is inbetween spaces, so if you use
for (int penguin = 0; penguin < numberOfProductions; penguin++)
{
// should read in single character that is on left...
Alright, try this, post a(1) specific-ish question, and the part of the code that goes with it
Thats alot to look through, as far as taking advantage of a space, I noticed in an earlier post a guy was having the opposite problem, I've been seeing this Scanner class alot, if you use a scanner...
public StateOfTurtle copyTurtle(StateOfTurtle oldTurtle) {
return new StateOfTurtle(oldTurtle.getX(), oldTurtle.getY(), oldTurtle.getAngle());
}
or even in stateofturtle class have that...
Sorry, alot of your questions are vague-ish to me and hard to answer. You could make a method to make a new object, and set it's values to that of a specified object pretty easily.