public Node<int> DuplicateListWithoutConsecutiveValueSequencesLongerThan2(Node<int> listHead)
{
var resultHead = new Node<int>(0, listHead);
var prevNode = resultHead;
var currentNode = listHead;
currentNode = currentNode.GetNext();
while (currentNode != null)
{
Node<int> nextNode = currentNode.GetNext();
int counter = 1;
while (nextNode != null && currentNode.GetValue() == nextNode.GetValue())
{
counter++;
nextNode = nextNode.GetNext();
}
if (counter >= 3){prevNode.SetNext(nextNode);}
else {prevNode = currentNode;}
currentNode = nextNode;
currentNode = currentNode.GetNext(); //If nodes get deleted it goes straight to the place after deletion, if not it goes the the place after checking the duplicates.
}
return listHead;
}
public Node<int> DuplicateListWithoutConsecutiveValueSequencesLongerThan2(Node<int> listHead)
{
var resultHead = new Node<int>(0, listHead);
var prevNode = resultHead;
var currentNode = listHead;
currentNode = currentNode.GetNext();
while (currentNode != null)
{
Node<int> nextNode = currentNode.GetNext();
int counter = 1;
while (nextNode != null && currentNode.GetValue() == nextNode.GetValue())
{
counter++;
nextNode = nextNode.GetNext();
}
if (counter >= 3){prevNode.SetNext(nextNode);}
else {prevNode = currentNode;}
currentNode = nextNode;
currentNode = currentNode.GetNext(); //If nodes get deleted it goes straight to the place after deletion, if not it goes the the place after checking the duplicates.