public void PopTest() { var list = new SLList <int>(1, 2, 3, 4, 5); Assert.AreEqual(5, list.Pop().UnwrapSuccess()); Assert.AreEqual(4, list.Length); }
static void Main(string[] args) { //TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true); TextWriter textWriter = new StreamWriter(Path.Combine(@"C:\A\hackerrank", "has_cycle_output.txt"), true); StreamReader reader = new StreamReader(Path.Combine(@"C:\A\hackerrank", "has_cycle_input.txt"), true); //int tests = Convert.ToInt32(Console.ReadLine()); int tests = Convert.ToInt32(reader.ReadLine()); for (int testsItr = 0; testsItr < tests; testsItr++) { int index = Convert.ToInt32(reader.ReadLine()); SLList llist = new SLList(); int llistCount = Convert.ToInt32(reader.ReadLine()); for (int i = 0; i < llistCount; i++) { int llistItem = Convert.ToInt32(reader.ReadLine()); llist.InsertNode(llistItem); } SLLNode extra = new SLLNode(-1); SLLNode temp = llist.head; for (int i = 0; i < llistCount; i++) { if (i == index) { extra = temp; } if (i != llistCount - 1) { temp = temp.next; } } temp.next = extra; bool result = hasCycle(llist.head); textWriter.WriteLine((result ? 1 : 0)); } textWriter.Flush(); textWriter.Close(); }
public void Example() { IEnumerable <int> MakeInts() { var i = 0; while (i < 100) { yield return(i++); } } //list construction var manualList = new SLList <int>(1, 2, 3, 4, 5); //using IEnumerable var list = new SLList <int>(MakeInts()); Console.WriteLine(); }
public static void Test() { SLList list = new SLList(); list.InsertAtBegining(15); list.InsertAtBegining(10); list.InsertAtBegining(5); list.InsertAtBegining(20); list.InsertAtBegining(3); list.InsertAtBegining(2); /* Sort the above created Linked List */ MergeSortForLinkedList obj = new MergeSortForLinkedList(); SLLNode head = list.Head; obj.MergeSort(ref head); obj.PrintList(list.Head); }
}//end of SLL class static void Main(string[] args) { Console.WriteLine("Hello World!"); // SLList myList = new SLList(); // myList.addToEnd("Hello"); // myList.addToEnd("Magical"); // myList.addToEnd("World"); // myList.PrintNodes(); // Console.WriteLine("*************************************"); // Console.WriteLine(myList.Contains("Hello")); // Console.WriteLine(myList.Contains("unicorn")); // Console.WriteLine(myList.Contains("World")); //myList.returnFirst(); //myList.addFront("A new string"); //myList.PrintNodes(); //Console.WriteLine("*************************************"); //Console.WriteLine(myList.removeFront()); //myList.PrintNodes(); //Console.WriteLine(myList.countNodes()); //myList.addAfterPosition("A new string", 2); //myList.PrintNodes(); //Console.WriteLine(myList.countNodes()); //Console.WriteLine(myList.returnEnd()); //Console.WriteLine(myList.removeEnd()); SLList myList2 = new SLList(); myList2.addToEnd(100); myList2.addToEnd(30); myList2.addToEnd(4); myList2.PrintNodes(); Console.WriteLine("*************************************"); Console.WriteLine(myList2.Max()); Console.WriteLine(myList2.Min()); Console.WriteLine(myList2.Average()); }
public void TestReverse() { SLLNode first = new SLLNode { Data = 1 }; first.Next = new SLLNode { Data = 2 }; first.Next.Next = new SLLNode { Data = 3 }; SLList.Print(first); //list.ReverseList(); Console.WriteLine(); //SLList.Print(list.Head); SLList.RecursiveReverse(ref first); SLList.Print(first); }