Microsoft Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
If I am not wrong linked list should have nextNode and prevNode, in-order to achieve insertion and deletion of an element at the beginning and end of the list.
So you leave the insertion/deletion/lookup code to the user of your class?
It is not as easy as you think.
class Node {
- hotcoder October 16, 2012int data;
Node nextNode;
public node(int data){
this.data= data;
}
public void setNode(Node next){
this.nextNode = next;
}
}
public static void main(String[] args){
int k= 10;
Node head = new Node(k); //first node
Node node = head;
for(i=0;i<6;i++){
Node next = new Node(i+k);//any value
node.setNode(next);
node=next;
}
}