internal
class
Node {
int
data;
Node next;
public
Node(
d) {
data = d;
next =
null
;
}
DNode {
DNode prev;
DNode next;
DNode(
prev =
SingleLinkedList {
Node head;
DoubleLinkedList {
DNode head;
void
InsertFront(SingleLinkedList singlyList,
new_data) {
Node new_node =
new
Node(new_data);
new_node.next = singlyList.head;
singlyList.head = new_node;
InsertFront(DoubleLinkedList doubleLinkedList,
data) {
DNode newNode =
DNode(data);
newNode.next = doubleLinkedList.head;
newNode.prev =
if
(doubleLinkedList.head !=
) {
doubleLinkedList.head.prev = newNode;
doubleLinkedList.head = newNode;
InsertLast(SingleLinkedList singlyList,
new_data)
{
(singlyList.head ==
return
Node lastNode = GetLastNode(singlyList);
lastNode.next = new_node;
InsertLast(DoubleLinkedList doubleLinkedList,
(doubleLinkedList.head ==
DNode lastNode = GetLastNode(doubleLinkedList);
lastNode.next = newNode;
newNode.prev = lastNode;
Node GetLastNode(SingleLinkedList singlyList) {
Node temp = singlyList.head;
while
(temp.next !=
temp = temp.next;
temp;
InsertAfter(Node prev_node,
(prev_node ==
Console.WriteLine(
"The given previous node Cannot be null"
);
new_node.next = prev_node.next;
prev_node.next = new_node;
InsertAfter(DNode prev_node,
data)
"The given prevoius node cannot be null"
newNode.next = prev_node.next;
prev_node.next = newNode;
newNode.prev = prev_node;
(newNode.next !=
newNode.next.prev = newNode;
DeleteNodebyKey(SingleLinkedList singlyList,
key)
Node prev =
(temp !=
&& temp.data == key) {
singlyList.head = temp.next;
&& temp.data != key) {
prev = temp;
(temp ==
prev.next = temp.next;
DeleteNodebyKey(DoubleLinkedList doubleLinkedList,
DNode temp = doubleLinkedList.head;
doubleLinkedList.head = temp.next;
doubleLinkedList.head.prev =
temp.next.prev = temp.prev;
(temp.prev !=
temp.prev.next = temp.next;
ReverseLinkedList(SingleLinkedList singlyList)
Node current = singlyList.head;
Node temp =
(current !=
temp = current.next;
current.next = prev;
prev = current;
current = temp;
singlyList.head = prev;
Conclusion