public void setPrevious(LinkListNode p) { prev = p; if (p != null && p.next != this) { p.setNext(this); } }
//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()); }
{//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()); }