public static void Main(string[] args) { LinkedList<string> linked = new LinkedList<string>(); // // Use AddLast method to add elements at the end. // Use AddFirst method to add element at the start. // linked.AddLast("Third"); linked.AddLast("Fourth"); linked.AddLast("Fifth"); linked.AddFirst("Second"); linked.AddLast("Sixth"); linked.AddFirst("First"); linked.RemoveFirst (); //linked.RemoveLast(); linked.Find("Fourth"); //linked.FindLast ("dog"); int x=linked.Count; Console.WriteLine (x); // Insert a node before the second node (after the first node) // LinkedListNode<string> node = linked.Find("Third"); linked.AddAfter(node, "inserted"); // // Loop through the linked list. foreach (string s in linked) Console.WriteLine (s); }
public static void Main() { var list = new LinkedList<int>(); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.Add(5); list.Add(3); list.Add(5); list.Add(10); Console.WriteLine("First index of element (5): {0}", list.FirstIndexOf(5)); Console.WriteLine("Last index of element (5): {0}", list.LastIndexOf(5)); Console.WriteLine("Count = {0}", list.Count); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.Remove(0); list.Remove(2); list.Remove(0); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); list.Remove(0); list.ForEach(Console.WriteLine); Console.WriteLine("--------------------"); }
static void Main(string[] args) { int[] inputA = new int[] { 7, 1, 6, 2 }; ListNode cycleNode = new ListNode(); ListNode node = new ListNode(); ListNode cycleNode2 = new ListNode(); cycleNode.Data = 10; cycleNode.Next = cycleNode2; cycleNode2.Data = 11; cycleNode.Next = node; node.Data = 3; node.Next = cycleNode; LinkedList.LinkedList listA = new LinkedList.LinkedList(); for (int i = 0; i < inputA.Length; i++) { listA.AddLast(new ListNode() { Data = inputA[i] }); } //listA.AddLast(node); Console.WriteLine(GetLoopNode(listA.Head).Data); Console.ReadLine(); }
public void ShouldReturnOneForOneElementList() { LinkedList<int> myList = new LinkedList<int>(); myList.Add(0); int result = myList.Count; Assert.Equal(1, result); }
private static void Main(string[] args) { // Creation ILinkedList<int> testList = new LinkedList<int>() { 1, 2, 3, 4, 5}; // Addition testList.Add(6); testList.Add(7); Console.WriteLine(string.Join(", ", testList)); // Enumerator // Removal testList.Remove(4); Console.WriteLine(string.Join(", ", testList)); Console.WriteLine("Contains 6: " + testList.Contains(6)); Console.WriteLine("Contains 4: " + testList.Contains(4)); int[] arr = new int[6]; testList.CopyTo(arr, 0); Console.WriteLine("Copied to array " + string.Join(", ", arr)); testList.AddAfter(6, 13); Console.WriteLine("Add after result " + string.Join(", ", testList)); testList.AddBefore(6, 13); Console.WriteLine("Add before result " + string.Join(", ", testList)); }
static void Main() { var list = new LinkedList<int>(); list.Add(1); list.Add(2); list.Add(3); list.Add(2); list.Add(2); Console.WriteLine("Count -> " + list.Count); foreach (var item in list) { Console.WriteLine(item); } Console.WriteLine("Remoeved at index 0 -> " + list.Remove(0)); Console.WriteLine("Count -> " + list.Count); foreach (var item in list) { Console.WriteLine(item); } Console.WriteLine("First index of 2 -> " + list.FristIdexOf(2)); Console.WriteLine("Last index of 2 -> " + list.LastIndexOf(2)); }
public static void Main() { LinkedList<int> myTestLinkedList = new LinkedList<int>(); myTestLinkedList.AddFirst(1); myTestLinkedList.AddLast(2); myTestLinkedList.AddLast(3); myTestLinkedList.AddLast(2); myTestLinkedList.AddLast(6); myTestLinkedList.AddLast(4); ListItem<int> itemInMiddle = myTestLinkedList.Find(3); myTestLinkedList.AddAfter(itemInMiddle, 10); myTestLinkedList.AddFirst(100); ListItem<int> currItem = myTestLinkedList.FirstElement; while (currItem.NextItem != null) { Console.WriteLine(currItem.Value); currItem = currItem.NextItem; } Console.WriteLine(currItem.Value); }
static void Main(string[] args) { var firstItem = new ListItem<int>(5, null); var linkedList = new LinkedList<int>(firstItem); //TODO: IMPLEMENT FUNCTIONS }
static void Main(string[] args) { int[] inputA = new int[] { 5, 6 }; LinkedList.LinkedList listA = new LinkedList.LinkedList(); for (int i = 0; i < inputA.Length; i++) { listA.AddLast(new ListNode() { Data = inputA[i] }); } int[] inputB = new int[] { 8, 4, 2 }; LinkedList.LinkedList listB = new LinkedList.LinkedList(); for (int i = 0; i < inputB.Length; i++) { listB.AddLast(new ListNode() { Data = inputB[i] }); } LinkedList.LinkedList listSum = new LinkedList.LinkedList(); listSum.Head = SumTwoNumbersLinkedList(listA.Head, listB.Head, carryForward); listSum.Print(); Console.ReadLine(); }
static void Main(string[] args) { LinkedList<int> list = new LinkedList<int>(); for (int i = 0; i < 10; i++) { list.Add(new Random().Next(0, 20)); Thread.Sleep(20); } list.AddRange(GetRandEnumerable(10)); foreach (var item in list) { Console.WriteLine(item); } Console.WriteLine(list.Contains(7)); Console.WriteLine(list.Find(7)); list.RemoveOneFirst(7); foreach (var item in list) { Console.WriteLine(item); } Console.ReadKey(); }
public static void Main() { try { LinkedList<int> linkedList = new LinkedList<int>(); linkedList.AddFirst(5); linkedList.AddLast(10); linkedList.AddFirst(20); // returns Exception //linkedList.AddItemAt(30, 0); linkedList.AddItemAt(30, 1); Console.WriteLine(linkedList[1]); linkedList.AddLast(50); linkedList.AddAfter(linkedList.FirstElement.NextItem.NextItem.NextItem, 60); linkedList.AddBefore(linkedList.FirstElement, 0); linkedList.RemoveFirst(); linkedList.RemoveLast(); linkedList.RemoveAt(1); Console.WriteLine(linkedList[1]); Console.WriteLine(linkedList.Count); linkedList.RemoveAt(5); } catch (ArgumentException aex) { Console.WriteLine(aex.TargetSite + " -> " + aex.Message); } catch (IndexOutOfRangeException iex) { Console.WriteLine(iex.TargetSite + " -> " + iex.Message); } }
public static ListNode ReverseInGroups(ListNode head, int k) { Stack <int> stack = new Stack <int>(k); LinkedList.LinkedList result = new LinkedList.LinkedList(); ListNode resultHead = null; ListNode current = head; while (current != null) { while (stack.Count < k && current != null) { stack.Push(current.Data); current = current.Next; } while (stack.Count > 0) { int data = stack.Pop(); result.AddLast(new ListNode(data)); resultHead = AddToLast(resultHead, new ListNode(data)); } } return(result.Head); }
public static void Main() { var myLinkedList = new LinkedList<int>(); myLinkedList.First = new ListItem<int>(1); Console.WriteLine(myLinkedList.First.Value); Console.WriteLine(myLinkedList.First.NextItem); }
public void ShouldAddTwoElementsAndReturnTworElementCountList() { LinkedList<int> myList = new LinkedList<int>(); myList.Add(0); myList.Add(4); int result = myList.Count; Assert.Equal(2, result); }
public static void driver() { LinkedList lnkd = new LinkedList(); lnkd.buildlist(10); lnkd.printList(); //lnkd.revIter(); lnkd.revRecur(lnkd.head); lnkd.printList(); }
static void Main() { var linkedList = new LinkedList<int>(); var firstListItem = new ListItem<int>(); firstListItem.Value = 1; linkedList.FirstElement = firstListItem; }
// Produces a randon number between minRange (inclusive) and maxRange (exclusive) and // generates a single linked list that is size of length. public void RunTests(uint minRange, uint maxRange, uint length) { Random random = new Random(); // Vetting insert works. for (int i = 0; i < length; ++i) { // if this is our head node if (i == 0) { myList = new LinkedList.LinkedList(random.Next((int)minRange, (int)maxRange)); continue; } myList.InsertSorted(random.Next((int)minRange, (int)maxRange)); } // Vet size of list is the same as length if (length != myList.GetSize()) { FailedTestCase("LENGTH"); } else { System.Console.WriteLine("PASSED: sizeof linked list expected: " + length + " actual: " + myList.GetSize()); } // Vetting its all sorted LinkedListNode.Node currentNode = myList.GetHeadNode(); int count = 1; //start count at 1 to count the Head; while (currentNode.GetNextNode() != null) { // check if current node is less than or equal to the next node if (currentNode.GetValue() <= currentNode.GetNextNode().GetValue()) { // so far its sorted, move to the next node currentNode = currentNode.GetNextNode(); } // we have a currentNode value that is > the nextNodes value, failed else { FailedTestCase("SORTING - currentNode: " + currentNode.GetValue() + " nextNodes value: " + currentNode.GetNextNode().GetValue()); break; } count++; } // Manual count to make sure all is accounted for System.Console.WriteLine("PASSED: Manual count " + count.ToString()); // Sorting test passed System.Console.WriteLine("PASSED: Sorting"); myList.PrintList(); }
static void Main(string[] args) { LinkedList list = new LinkedList(); list.Add("Test1"); list.Add("Test2"); list.Add("Test3", 1); list.Remove(1); list.Clear(); }
static void Main() { var linkedList = new LinkedList<int>(); for (int i = 0; i < 10; i++) { linkedList.Add(i); } Console.WriteLine(string.Join(", ", linkedList)); }
public void ShouldCheckIfInsertBeforeIndex3Works() { var list = new LinkedList<int>() { 9, 2, 7, 5 }; list.InsertBefore(3, 3); int[] result = new int[] { 9, 2, 7, 3, 5 }; Assert.Equal(result, list); Assert.Equal(5, list.Count); }
public void ShouldCheckIfInsertAfterIndex0Works() { var list = new LinkedList<int>() { 9, 2, 7, 5 }; list.InsertAfter(3, 0); int[] result = new int[] { 9, 3, 2, 7, 5 }; Assert.Equal(result, list); Assert.Equal(5, list.Count); }
public void ShouldReturnAnArrayWithElementsFromList() { LinkedList<int> myList = new LinkedList<int>(); myList.Add(0); myList.Add(4); myList.Add(7); int[] result = new int[3]; myList.CopyTo(result,0); int[] expected = { 0, 4, 7 }; Assert.Equal(expected,result); }
public void ShouldReturnAnArrayWithElementsFromListStartingFromOne() { LinkedList<int> myList = new LinkedList<int>(); myList.Add(3); myList.Add(4); myList.Add(7); int[] result = new int[2]; myList.CopyTo(result, 1); int[] expected = { 0, 3 }; Assert.Equal(expected, result); }
public void ShouldRemoveFirstElementWithValueFour() { LinkedList<int> myList = new LinkedList<int>(); myList.Add(0); myList.Add(4); myList.Add(7); myList.Remove(4); int[] expected = { 0, 7 }; int[] result = new int[2]; myList.CopyTo(result, 0); Assert.Equal(expected, result); }
static void Main(string[] args) { LinkedList<int> list = new LinkedList<int>(); list.AddToEnd(3); list.AddToEnd(8); list.AddToFront(5); list.DeleteFromEnd(); list.DeleteFromHead(); list.Display(); Console.WriteLine(list.Search(7)); }
public void ShouldCheckIfValueAtIndexIsRemoved() { var list = new LinkedList<int>() { 9, 2, 7, 5 }; //list.Remove(2); //int[] result = new int[] { 9, 2, 5 }; list.Remove(0); int[] result = new int[] { 2, 7, 5 }; Assert.Equal(result,list); Assert.Equal(3, list.Count); }
/** * Initiates the program by constructing and editing a linked list. * * @param args command line arguments */ static void Main(string[] args) { LinkedList list = new LinkedList(); list.add("Thomas"); list.add("Curtis"); list.add("Zach"); Console.WriteLine(list.getHead().data); Console.WriteLine("Lets print the entire list\n"); Console.WriteLine(list.ToString()); Console.ReadLine(); }
static void Main(string[] args) { LinkedList<int> test = new LinkedList<int>(); test.Add(0); test.Add(1); test.Add(2); test.Add(3); test.Add(3); test.Remove(0); Console.WriteLine(test.FirstIndexOf(2)); Console.WriteLine(test.LastIndexOf(3)); }
public static void Main() { LinkedList<int> list = new LinkedList<int>(); list.AddFirst(5); list.AddFirst(1); list.AddLast(-10); list.AddLast(8); list.AddFirst(3); foreach (var item in list) { Console.WriteLine(item); } }
static void Main(string[] args) { LinkedList<string> list = new LinkedList<string>(); list.Add("x"); list.Add("g"); list.Add("s"); Console.WriteLine(list.Count); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } list.InsertAfter("g", "a"); Console.WriteLine(); Console.WriteLine(); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } //list.InsertAt(10, "z"); Console.WriteLine(); Console.WriteLine(); list.InsertAt(2, "z"); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } Console.WriteLine(); Console.WriteLine(); list.RemoveAt(2); for (int i = 0; i < list.Count; i++) { Console.WriteLine(list[i]); } //Console.WriteLine(list[2]); }
public static void Main() { var numbers = new LinkedList<int>(); numbers.AddFirst(1); numbers.AddFirst(2); numbers.AddFirst(3); numbers.AddFirst(4); numbers.AddLast(5); numbers.AddLast(6); numbers.AddLast(7); int numberOfElements = numbers.Count; Console.WriteLine(NumberOfElementsMessage, numberOfElements); numbers.Print(); }
public static void Main() { var linkedList = new LinkedList<int>(); linkedList.Add(5); linkedList.Add(10); linkedList.Add(42); linkedList.Add(45); linkedList.Add(5); linkedList.Remove(5); linkedList.Remove(45); Console.WriteLine(linkedList.Contains(42)); foreach (var item in linkedList) { Console.WriteLine(item); } }
public static void Main() { LinkedList<int> list = new LinkedList<int>(); ListItem<int> head = new ListItem<int>(1337); list.FirstElement = head; ListItem<int> secondElement = new ListItem<int>(666); head.NextItem = secondElement; secondElement.NextItem = new ListItem<int>(42); foreach (var item in list) { Console.WriteLine(item); } }
static void Main(string[] args) { int[] input = new int[] { 1, 2, 3, 1, 3, 2, 1 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } Console.WriteLine(IsPalindromeRec(list.Head)); //Console.WriteLine(IsPalindrome(list.Head)); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 1, 2, 3, 4, 5, 6, 7 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } Fold(list.Head); Console.ReadLine(); }
public void TestReverse() { LinkedList<int> ll = new LinkedList<int>(); ll.AddFirst(9); ll.AddFirst(8); ll.AddFirst(7); ll.AddFirst(6); ll.AddFirst(5); ll.AddFirst(4); ll.AddFirst(3); ll.AddFirst(2); ll.AddFirst(1); ll.Reverse(); int[] myAnswer = ll.ToArray(); int[] answer = new int[] { 9, 8, 7, 6, 5, 4, 3, 2, 1 }; for (int i = 0; i < answer.Length; i++) { Assert.AreEqual(answer[i], myAnswer[i]); } LinkedList<int> l2 = new LinkedList<int>(); l2.AddFirst(9); l2.AddFirst(8); l2.AddFirst(7); l2.AddFirst(6); l2.AddFirst(5); l2.AddFirst(4); l2.AddFirst(3); l2.AddFirst(2); l2.AddFirst(1); l2.ReverseRecursive(); int[] myRecursiveAnswer = l2.ToArray(); for (int i = 0; i < answer.Length; i++) { Assert.AreEqual(answer[i], myRecursiveAnswer[i]); } }
//Below method works correctly //public static ListNode MergeSort(ListNode head) //{ // if (head == null) return null; // if (head.Next == null) return head; // int length = GetLength(head); // int mid = length / 2; // LinkedList.LinkedList listA = new LinkedList.LinkedList(); // LinkedList.LinkedList listB = new LinkedList.LinkedList(); // for (int i = 0; i <= length - 1; i++) // { // ListNode temp = new ListNode(); // temp.Data = head.Data; // if (i < mid) // { // listA.AddLast(temp); // } // else // { // listB.AddLast(temp); // } // head = head.Next; // } // var sortedHeadA = MergeSort(listA.Head); // var sortedHeadB = MergeSort(listB.Head); // return MergeLists(sortedHeadA, sortedHeadB); //} private static ListNode MergeLists(ListNode head1, ListNode head2) { if (head1 == null) { return(head2); } if (head2 == null) { return(head1); } LinkedList.LinkedList result = new LinkedList.LinkedList(); while (head1 != null && head2 != null) { ListNode temp = new ListNode(); if (head1.Data <= head2.Data) { temp.Data = head1.Data; head1 = head1.Next; } else { temp.Data = head2.Data; head2 = head2.Next; } result.AddLast(temp); } if (head1 != null) { result.AddLast(head1); } if (head2 != null) { result.AddLast(head2); } return(result.Head); }
public static ListNode MergeAlternateIterative(ListNode headA, ListNode headB) { if (headA == null && headB == null) { return(null); } if (headA == null) { return(headB); } if (headB == null) { return(headA); } LinkedList.LinkedList result = new LinkedList.LinkedList(); while (headA != null && headB != null) { ListNode tempA = new ListNode(); ListNode tempB = new ListNode(); tempA.Data = headA.Data; tempB.Data = headB.Data; tempA.Next = tempB; result.AddLast(tempA); headA = headA.Next; headB = headB.Next; } if (headA != null) { result.AddLast(headA); } if (headB != null) { result.AddLast(headB); } return(result.Head); }
public void TestPrint2() { LinkedList.LinkedList linkedList = new LinkedList.LinkedList(); linkedList.AddFront(1); linkedList.AddFront(2); linkedList.AddFront(3); linkedList.AddFront(4); linkedList.AddFront(5); List <int> expextedResult = new List <int>() { 5, 4, 3, 2, 1 }; List <int> result = new List <int>(); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(expextedResult[i], result[i]); } }
static void Main(string[] args) { int[] input = new int[] { 1, 5, 2, 3, 4, 2, 5, 9 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } list.Print(); Console.WriteLine(); Console.WriteLine(KthNodeFromEnd(list.Head, 5)); Console.WriteLine(KthNodeFromEndAlt(list.Head, 5)); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 12, 15, 10, 11, 5, 6, 2, 3 }; //int[] input = new int[] { 10, 20, 30, 40, 50 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } LinkedList.LinkedList listA = new LinkedList.LinkedList(); listA.Head = RemoveIfGreaterAtRight(list.Head); listA.Print(); Console.ReadLine(); }
public void TestDeleteFront() { LinkedList.LinkedList linkedList = new LinkedList.LinkedList(); linkedList.Add(1); linkedList.Add(2); linkedList.Add(3); linkedList.Add(4); linkedList.Add(5); linkedList.DeleteFront(); List <int> expextedResult = new List <int>() { 2, 3, 4, 5 }; List <int> result = new List <int>(); for (int i = 0; i < result.Count; i++) { Assert.AreEqual(expextedResult[i], result[i]); } }
static void Main(string[] args) { int[] input = new int[] { 1, 5, 2, 3, 4, 2, 5, 9 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } list.Print(); Console.WriteLine(); DeleteMiddleNode(list.Head.Next.Next); list.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] inputA = new int[] { 7, 1, 6, 2 }; ListNode node = new ListNode(); node.Data = 3; node.Next = new ListNode() { Data = 10 }; LinkedList.LinkedList listA = new LinkedList.LinkedList(); for (int i = 0; i < inputA.Length; i++) { listA.AddLast(new ListNode() { Data = inputA[i] }); } int[] inputB = new int[] { 5, 9, 6, 2 }; LinkedList.LinkedList listB = new LinkedList.LinkedList(); for (int i = 0; i < inputB.Length; i++) { listB.AddLast(new ListNode() { Data = inputB[i] }); } listA.AddLast(node); listB.AddLast(node); Console.WriteLine(GetIntersection(listA.Head, listB.Head).Data); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 0, 1, 3, 0, 4, 0, 9 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.InsertAtEnd(new LinkedList.ListNode() { Data = input[i] }); } list.Print(); list.Head = MoveZerosToFront2(list.Head); list.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] inputA = new int[] { 10, 3, 2, 11, 34, 1, 76 }; LinkedList.LinkedList listA = new LinkedList.LinkedList(); for (int i = 0; i < inputA.Length; i++) { listA.AddLast(new ListNode() { Data = inputA[i] }); } listA.Print(); LinkedList.LinkedList list = new LinkedList.LinkedList(); list.Head = MergeSort(listA.Head); list.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 1, 5, 2, 3, 4, 2, 5, 9 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } list.Print(); Console.WriteLine(); RemoveDupsWithoutBuffer(list.Head); //RemoveDups(list.Head); list.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 2, 1, 3, 4, 5, 6, 7 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } list.Print(); Console.WriteLine(); list.Head = MoveEvenToFront(list.Head); list.Print(); Console.WriteLine(); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 1, 2, 3, 4, 5 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.InsertAtEnd(new LinkedList.ListNode() { Data = input[i] }); } list.Print(); //list.Head = ReversePairRecursive(list.Head); list.Head = ReversePairIterative(list.Head); list.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 1, 2, 3, 4, 5, 6, 7 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } list.Print(); LinkedList.LinkedList test = new LinkedList.LinkedList(); LinkedList.LinkedList testB = new LinkedList.LinkedList(); test.Head = ReverseInGroups(list.Head, 2); //testB.Head = ReverseInPairs(list.Head); //test.Head = ReverseInGroupsRecursive(list.Head, 3); test.Print(); //testB.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 3, 5, 8, 5, 10, 2, 1 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } list.Print(); Console.WriteLine(); //Partition(list.Head, 5); PartitionAlt(list.Head, 5); list.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] inputA = new int[] { 7, 1 }; LinkedList.LinkedList listA = new LinkedList.LinkedList(); for (int i = 0; i < inputA.Length; i++) { listA.AddLast(new ListNode() { Data = inputA[i] }); } int[] inputB = new int[] { 5, 9, 2 }; LinkedList.LinkedList listB = new LinkedList.LinkedList(); for (int i = 0; i < inputB.Length; i++) { listB.AddLast(new ListNode() { Data = inputB[i] }); } LinkedList.LinkedList sum = new LinkedList.LinkedList(); sum.Head = SumLists(listA.Head, listB.Head); LinkedList.LinkedList sumForwardRepresentation = new LinkedList.LinkedList(); sumForwardRepresentation.Head = SumListsForwardRepresentation(listA.Head, listB.Head); sum.Print(); sumForwardRepresentation.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] input = new int[] { 1, 2, 3, 4, 5, 6, 7 }; LinkedList.LinkedList list = new LinkedList.LinkedList(); for (int i = 0; i < input.Length; i++) { list.AddLast(new ListNode() { Data = input[i] }); } list.Print(); LinkedList.LinkedList test = new LinkedList.LinkedList(); test.Head = ReverseList(list.Head); ///test.Head = ReverseListIterative(list.Head); test.Print(); Console.ReadLine(); }
static void Main(string[] args) { int[] inputA = new int[] { 1, 3, 5, 7, 9 }; LinkedList.LinkedList listA = new LinkedList.LinkedList(); for (int i = 0; i < inputA.Length; i++) { listA.AddLast(new ListNode() { Data = inputA[i] }); } int[] inputB = new int[] { 2, 4, 6, 8, 10, 11, 12, 13 }; LinkedList.LinkedList listB = new LinkedList.LinkedList(); for (int i = 0; i < inputB.Length; i++) { listB.AddLast(new ListNode() { Data = inputB[i] }); } LinkedList.LinkedList result = new LinkedList.LinkedList(); result.Head = MergeAlternate(listA.Head, listB.Head); result.Print(); LinkedList.LinkedList resultA = new LinkedList.LinkedList(); resultA.Head = MergeAlternateIterative(listA.Head, listB.Head); resultA.Print(); Console.ReadLine(); }
static void Main(string[] args) { LinkedList.LinkedList lista1 = new LinkedList.LinkedList(); lista1.add(1); lista1.add(4); lista1.add(3); lista1.add(7); Iterator it = lista1.getIterator(); System.Console.WriteLine("-----Imprimimos Lista Original-----"); while (it.hasNext()) { int element = it.next(); System.Console.WriteLine("Dato: " + element); } System.Console.WriteLine("-----Insertamos según posición-----"); it = lista1.getIterator(); while (it.hasNext()) { Iterator backupIt = new Iterator(it); int element = it.next(); if (element == 3) { lista1.insert(10, LinkedList.LinkedList.BEFORE, backupIt); } if (element == 7) { lista1.insert(15, LinkedList.LinkedList.AFTER, backupIt); } } it = lista1.getIterator(); while (it.hasNext()) { int element = it.next(); System.Console.WriteLine("Dato: " + element); } System.Console.WriteLine("-----Eliminamos el valor 3-----"); lista1.delete(3); System.Console.WriteLine("--- El tamaño es:" + lista1.getSize() + " ---"); it = lista1.getIterator(); while (it.hasNext()) { int element = it.next(); System.Console.WriteLine("Dato: " + element); } System.Console.WriteLine("-----Recorremos la lista con el ReverseIterator-----"); ReverseIterator reverseIterator = lista1.getReverseIterator(); while (reverseIterator.hasNext()) { int element = reverseIterator.next(); System.Console.WriteLine("Dato: " + element); } Console.ReadKey(); Console.ReadKey(); }