1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
public class ListInt
{
protected int size;
class NodeInt
{
protected int data;
protected NodeInt next;
public NodeInt(final int data)
{
this.data = data;
next = null;
}
public boolean hasNext()
{
return next != null;
}
public NodeInt next()
{
return next;
}
public int getData()
{
return data;
}
}
protected NodeInt head, tail;
public ListInt()
{
size = 0;
head = tail = null;
}
public NodeInt getHead()
{
return head;
}
public boolean isEmpty()
{
return head == tail;
}
public void add(final int data)
{
if (size == 0)
{
head = new NodeInt(data);
tail = head;
}
else
{
tail.next = new NodeInt(data);
tail = tail.next;
}
size++;
}
} |
Partager