Код: Выделить всё
public class SLList {
public class IntNode {
public int item;
public IntNode next;
public IntNode(int item, IntNode next){
this.item = item;
this.next = next;
}
}
private IntNode first;
public SLList(int x){
this.first = new IntNode(x, null);
}
public void addFirst(int n){
first = new IntNode(n, first);
}
public int getFirst(){
return first.item;
}
}
Код: Выделить всё
public class SLListTest {
@Test
public void addFirst() {
SLList s = new SLList(10);
s.addFirst(5);
Assert.assertEquals(5, s.getFirst());
}
@Test
public void getFirst() {
SLList s = new SLList(10);
s.addFirst(5);
Assert.assertEquals(5, s.getFirst());
}
}
Подробнее здесь: https://stackoverflow.com/questions/695 ... ss-in-java
Мобильная версия