Interview Questions

Implement (in C++ or C#) a function that removes the nth element of a single linked list. .....

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

Implement (in C++ or C#) a function that removes the nth element of a single linked list. .....

Question:
#1 Implement (in C++ or C#) a function that removes the nth element of a single linked list.

C++:
class Node
{

char* value;
Node* next;
};
Node** RemoveNth (Node** list, int n)
{
}
C#:
class Node
{

string value;
Node next;
}
Node RemoveNth(Node list, int n)
{
}
#2. Using the following table provide at least 5 test cases to test the function implemented in the previous part.
Node n Expected Result



maybe an answer:


1. 'n' is somewhere in the middle of the list. //free memory & remove it from list.
2. 'n' = 0. Removing the first element. // update header to next & free up 1st element.
3. 'n' = last element. // update the list - last element.
4. list has only 1 element. and n = that element. // free it & make list null.
5. 'n' not in the list. // Return the same list
6. what if list is circular &'n' is not in the list? // write some detectCircular() method to check this.
7. test when n is a negative number. Sound ridiculous but we can not guarantee n > -1.

(Continued on next question...)

Other Interview Questions