Skip to content

Instantly share code, notes, and snippets.

@eduuh
Created February 22, 2022 14:24
Show Gist options
  • Save eduuh/7f0d7e1acadb1120abc98b7be81302d0 to your computer and use it in GitHub Desktop.
Save eduuh/7f0d7e1acadb1120abc98b7be81302d0 to your computer and use it in GitHub Desktop.
using System;
namespace Algorithms {
class CustomLinkedList {
Node head;
public class Node {
public int data;
public Node next;
public Node(int d)
{
data = d;
next = null;
}
}
public Boolean hasCycle() {
return false;
}
static void Main(string[] args) {
CustomLinkedList noCycleLinkedList = new CustomLinkedList();
Node firstNode = new Node(3);
Node secondNode = new Node(4);
Node thirdNode = new Node(5);
Node fourthNode = new Node(6);
noCycleLinkedList.head = firstNode;
firstNode.next = secondNode;
secondNode.next = thirdNode;
thirdNode.next = fourthNode;
Console.WriteLine(noCycleLinkedList.hasCycle());
CustomLinkedList cycleLinkedList = new CustomLinkedList();
cycleLinkedList.head = firstNode;
thirdNode.next = secondNode;
Console.WriteLine(cycleLinkedList.hasCycle());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment