| Thread Closed |
Using LRStruct to pass a test |
Share Thread | Thread Tools |
| Feb16-10, 03:21 PM | #1 |
|
|
Using LRStruct to pass a test
1. Define this method so that it adds the Strings in inputto an initially empty LRStruct<String> so that they appearin the same order. Example: if input contains "a", "b" and "c", in that order, the returned list must contain "a", "b" and "c", in that order.
LRStruct Class: http://www.cs.rice.edu/~mgricken/res.../LRStruct.html Test: Code:
@Test
public void testABC() {
_input.add("a");
_input.add("b");
_input.add("c");
LRStruct<String> answer = _fwl.addInOrder(_input);
String expected = "(a b c)";
String actual = answer.toString();
assertTrue("I thought answer would be "+expected+" but it was "+actual, expected.equals(actual));
}
2. Here's my attempt at the method addInOrder. All I'm getting is the string c to add to the LRStruct. Not sure why my if statement isn't working correctly. Code:
public LRStruct<String> addInOrder(List<String> input) {
LRStruct<String> lrstruct = new LRStruct<String>();
int counter = 2;
if(counter>=0){
lrstruct.insertFront(input.get(counter));
counter--;
}
return lrstruct;
}
|
| Feb16-10, 08:41 PM | #2 |
|
|
I think what you're looking for is a loop. I.e.:
Code:
int counter = 2;
if(counter>=0){
lrstruct.insertFront(input.get(counter));
counter--;
}
Code:
lrstruct.insertFront(input.get(2)); |
| Feb16-10, 09:12 PM | #3 |
|
|
Okay I understand that but thats the exact same thing I wrote. That's not helping me.
|
| Feb17-10, 12:41 AM | #4 |
|
|
Using LRStruct to pass a test
You need a loop
Doesn't Java have while loops, or for loops? Or for-each loops? |
| Thread Closed |
| Thread Tools | |
Similar Threads for: Using LRStruct to pass a test
|
||||
| Thread | Forum | Replies | ||
| Can you pass the smile test? | General Discussion | 68 | ||
| RL High-Pass/Low-Pass Filters | Engineering, Comp Sci, & Technology Homework | 4 | ||
| MATLAB low pass and high pass | Engineering, Comp Sci, & Technology Homework | 0 | ||
| High Pass filter & Low Pass Filters features | Engineering, Comp Sci, & Technology Homework | 1 | ||
| Could your management skills pass the test? | Computing & Technology | 0 | ||