What does this class represent exactly?

Hi guys, I have missed a lot of computer class in school (-_-) and am looking for a bit of help. I have the following class (generic list, at the end of the post). I want to know what exactly this is, a linked list, an array list just a list (does that even exist?). From what I understand this is a linked list, in a generic shape. The node class in use is a generic node class, nothing special just the regular _next and _data sort of thing.
Secondly I was wondering what the heck is going on in the insert (add) method? There are no notes in the code and I'm not sure what the parameters represent... For example what would pos (position) be fore?
I tried following with an example but I'm not really getting it.
My guess is that pos is a position int he list, but then wouldn't we need a while loop to find that pos and then insert the new node into that area? or is there some way to access a area in the list like with an array?
Lots of questions, I hope you can help out.

CLASS:
[code]

public class List
{
private Node first;

public List()
{
this.first=null;
}

public boolean isEmpty()
{
return this.first==null;
}

public Node getFirst()
{
return this.first;
}

public Node insert(Node pos, T x)
{
Node node = new Node(x);

if(pos == null)
{
node.setNext(this.first);
this.first = node;
}
else
{
node.setNext(pos.getNext());
pos.setNext(node);
}
return(node);
}

public Node remove(Node pos)
{
if(this.first == pos)
this.first = pos.getNext();
else
{
Node prevPos = this.getFirst();
while(prevPos.getNext() != pos)
prevPos = prevPos.getNext();
prevPos.setNext(pos.getNext());
}

Node nextPos = pos.getNext();
pos.setNext(null);

return nextPos;
}


public String toString()
{
String st="{";
Node pos=this.first;
while (pos!=null)
{
st=st+pos.getInfo().toString();
if (pos.getNext()!=null)
st=st+",";
pos=pos.getNext();
}
st=st+"}";
return st;
}
}

[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories