Using LRStruct to pass a test

  • Thread starter MFlood7356
  • Start date
  • #1
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/re...ce_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));
	}



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;
	}
 

Answers and Replies

  • #2
284
0
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--;
		}
will do the exact same thing as
Code:
lrstruct.insertFront(input.get(2));
 
  • #3
39
0
Okay I understand that but thats the exact same thing I wrote. That's not helping me.
 
  • #4
284
0
You need a loop

Doesn't Java have while loops, or for loops? Or for-each loops?
 

Related Threads on Using LRStruct to pass a test

  • Last Post
Replies
1
Views
1K
Replies
0
Views
2K
  • Last Post
Replies
1
Views
2K
Replies
2
Views
5K
  • Last Post
Replies
3
Views
5K
Replies
2
Views
998
  • Last Post
Replies
4
Views
19K
Top