Convert a Single Linked List to a Double Linked List

Technology CommunityCategory: Linked ListsConvert a Single Linked List to a Double Linked List
VietMX Staff asked 3 years ago

A doubly linked list is simply a linked list where every element has both next and prev mebers, pointing at the elements before and after it, not just the one after it in a single linked list.

so to convert your list to a doubly linked list, just change your node to be:

private class Node
{
    Picture data;
    Node pNext;
    Node pPrev;
};

and when iterating the list, on each new node add a reference to the previous node.