I was given 15 minutes to write the code to reverse a singly-linked list.

What do you think of the code style here?

using Microsoft.VisualStudio.TestTools.UnitTesting;

{
[TestClass]
{
[TestMethod]
{
Node<int> two = new Node<int>();
Node<int> three = new Node<int>();
Node<int> four = new Node<int>();
two.Value = 2;
two.Next = three;
three.Value = 3;
three.Next = four;
four.Value = 4;
}
}

{
public static void Reserve(ref Node<int> head)
{
Node<int> previous = null;
while (current != null)
{
Node<int> temp = current.Next;
current.Next = previous;
previous = current;
current = temp;
}
}
}

public class Node<T>
{
public T Value { get; set; }
public Node<T> Next { get; set; }
}
}

• What exactly was the interview question (any specific requirements beyond 'reverse a linked list')? And what kind of feedback are you looking for? – Pieter Witvoet Aug 9 '18 at 7:57
• I think you know that posting a code-only question like this one is off-topic, don't you? ;-) – t3chb0t Aug 9 '18 at 8:15
• @PieterWitvoet and t3chb0t thanks for the comments – Gilad Aug 9 '18 at 8:25
• @t3chb0t Code-only questions are not off-topic by default. – Snowhawk Aug 9 '18 at 11:51
• @Snowhawk well, you should read the linked question. The discussion goes in a slightly different direction there, towards closing and off-topicness. I find it's just plain rude to post code and let people figure out the rest by themselves. – t3chb0t Aug 9 '18 at 12:00

Two of the methods use the word Reserve instead of Reverse: ReservseLinkedListTest and Reserve.