//Update public void Add(int val) { if (head == null) { head = new DLNode(val); tail = new DLNode(val); } else { DLNode curr = tail; curr.next = new DLNode(val); tail = curr.next; } Count++; }
//Read pt 1 public Boolean Contains(int val) { DLNode curr = head; while (curr != null) { if (curr.val == val) { return(true); } else { curr = curr.next; } } return(false); }
public int Captcha1() { int result = 0; int lCount = 0; DLNode curr = head; while (lCount < Count) { if (curr.val == curr.last.val) { result += curr.val; } lCount++; curr = curr.next; } return(result); }
public void Add(int val) { if (head == null) { head = new DLNode(val); head.next = head; head.last = head; tail = head; } else { tail.next = new DLNode(val); tail.next.next = head; tail.next.last = tail; tail = tail.next; } }
public CLL AddChar(string val) { if (head == null) { head = new DLNode(Convert.ToInt32(val)); head.next = head; head.last = head; tail = head; } else { tail.next = new DLNode(Convert.ToInt32(val)); tail.next.next = head; tail.next.last = tail; tail = tail.next; } return(this); }
public CLL StringToCLL(string val) { foreach (char item in val) { if (head == null) { head = new DLNode(Convert.ToInt32(item)); head.next = head; head.last = head; tail = head; } else { tail.next = new DLNode(Convert.ToInt32(item)); tail.next.next = head; tail.next.last = tail; tail = tail.next; } } return(this); }
//Delete public DLNode Remove(int val) { DLNode result = null; if (!Contains(val)) { return(null); } else if (head.val == val && head == tail) { result = head; head = null; tail = null; } else if (head.val == val) { result = head; head = head.next; } else { DLNode curr = head; while (curr.next != null) { if (curr.next.val == val) { result = curr.next; if (tail == curr.next) { tail = curr; } curr.next = curr.next.next; } curr = curr.next; } } Count--; return(result); }
public DLNode(int val) { this.val = val; next = null; last = null; }
//Create public DLL() { head = null; tail = null; Count = 0; }