public String printForward() { if (next != null) { return(data + "->" + next.printForward()); } else { return(data.ToString()); } }
{//Write code to remove duplicates from an unsorted link. Follow up: how would you solve this problem if a temp buffer is not allowed? static void Main(string[] args) { LinkListNode first = new LinkListNode(0, null, null); LinkListNode head = first; LinkListNode second = first; for (int i = 1; i < 8; i++) { second = new LinkListNode(i % 2, null, null); first.setNext(second); second.setPrevious(first); first = second; } LinkListNode cloneA = head.clone(); LinkListNode cloneB = head.clone(); Console.WriteLine(cloneA.printForward()); removeDupe(cloneA); Console.WriteLine(cloneA.printForward()); Console.WriteLine(cloneB.printForward()); removeDupe2(cloneB); Console.WriteLine(cloneB.printForward()); }