public void Reverse() { DllNode runner = Head; DllNode previous; if (runner == Head) { runner.Prev = runner.Next; runner.Next = null; } while (runner != null) { previous = runner; runner = runner.Prev; if (runner.Next == null) { previous.Prev = runner; Head = runner; runner.Next = previous; break; } else { runner.Prev = runner.Next; runner.Next = previous; } } }
public void Add(int value) { DllNode newNode = new DllNode(value); if (Head == null) { Head = newNode; } else { DllNode runner = Head; DllNode previous; while (runner.Value != null) { previous = runner; runner = runner.Next; if (runner == null) { previous.Next = newNode; newNode.Prev = previous; break; } } } }
public DllNode(int val) { // your code here Value = val; Next = null; Prev = null; }
public void PrintValues() { DllNode runner = Head; while (runner != null) { System.Console.WriteLine(runner.Value); runner = runner.Next; } }
public void Display() { DllNode runner = Head; while (runner != null) { Console.WriteLine(runner.Value); runner = runner.Next; } }
// Place your methods here. public void Add(int val) { DllNode NewNode = new DllNode(val); DllNode runner = this.Head; while (runner.Next != null) { runner = runner.Next; } runner.Next = NewNode; }
public void PrintValues() { DllNode runner = Head; while (runner != null) { Console.WriteLine($"{runner.Value}"); if (runner.Next != null) { runner = runner.Next; } else { break; } } }
public void Reverse() { DllNode runner = Head; while (runner != null) { if (runner.Next == null) { Head = runner; } DllNode temp = runner.Prev; DllNode tempNext = runner.Next; runner.Prev = runner.Next; runner.Next = temp; runner = tempNext; } }
public bool Remove(int value) { DllNode runner = Head; while (runner.Value != value && runner != null) { runner = runner.Next; } if (runner == null) { return(false); } else { DllNode previousItem = runner.Prev; previousItem.Next = runner.Next; return(true); } }
public void Add(int value) { DllNode newNode = new DllNode(value); if (Head == null) { Head = newNode; } else { DllNode runner = Head; while (runner.Next != null) { runner = runner.Next; } runner.Next = newNode; newNode.Prev = runner; } }
public bool Remove(int value) { DllNode runner = Head; DllNode previous; DllNode nextup; if (Head.Value == value) { previous = Head; Head.Next = Head; previous.Next = null; Head.Prev = null; return(true); } else { while (runner.Value != value) { previous = runner; runner = runner.Next; if (runner.Value == value) { if (runner.Next == null) { previous.Next = null; runner.Prev = null; return(true); } else { nextup = runner.Next; previous.Next = nextup; nextup.Prev = previous; runner.Next = null; runner.Prev = null; return(true); } } } } Console.WriteLine("Values didn't match"); return(false); }
// Place your methods here. public DoublyLinkedList Add(int value) { DllNode newNode = new DllNode(value); if (Head == null) { Head = newNode; return(this); } else { DllNode runner = Head; while (runner.Next != null) { runner = runner.Next; } runner.Next = newNode; newNode.Prev = runner; return(this); } }
public bool Remove(int value) { bool check = false; DllNode runner = Head; while (runner.Next != null) { if (runner.Value == value) { check = true; DllNode temp = runner; runner.Prev.Next = runner.Next; runner.Next.Prev = temp.Prev; break; } runner = runner.Next; } return(check); }
public void Reverse() { DllNode temp = null; DllNode current = Head; /* swap next and prev for all nodes of * doubly linked list */ while (current != null) { temp = current.Prev; current.Prev = current.Next; current.Next = temp; current = current.Prev; } /* Before changing head, check for * the cases like empty list and * list with only one node */ if (temp != null) { Head = temp.Prev; } }
public DllNode(int val) { Value = val; Next = null; Prev = null; }
public DLinkedLists() { Head = null; }
public DoublyLinkedList() { Head = null; }