- #1
MFlood7356
- 39
- 0
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/research/a4obj1st/tchjava/Rice_MBS/RiceMBS.student/docs/lrs/LRStruct.html
Test:
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.
LRStruct Class: http://www.cs.rice.edu/~mgricken/research/a4obj1st/tchjava/Rice_MBS/RiceMBS.student/docs/lrs/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));
}
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;
}