Page cover

Doubly Linked List

main.cpp
#include "DoublyLinkedList.h"

int main() {  
    DoublyLL list;
    list.insert(1);
    list.insert(2);
    list.insertAtHead(3);
    list.insertAtHead(4);
    list.insertAtHead(5);
    
    cout << "Main List: " << list << endl;
    
    cout << "Given Node Data Present: " << boolalpha << list.search(1) << endl << endl;

    int temp;
    cout << "Head Removed: " << boolalpha << list.removeHead(temp) << endl;
    cout << "Deleted Head Node Element: " << temp << endl;
    cout << list << endl;

    cout << "Tail Node Removed: " << boolalpha << list.remove(2) << endl;
    cout << list << endl;

    cout << "Random Node Removed: " << boolalpha << list.remove(3) << endl;
    cout << list << endl;

    // --> There are some bugs in clear functions
    // list.clear();

    // cout << "List is Empty: " << boolalpha << list.isEmpty() << endl;
    
    // --> checking assignment & copy constructor
    
    // DoublyLL list1;
    // list1.insert(1);
    // list1.insert(2);
    // list1.insertAtHead(3);
    // list1.insertAtHead(4);
    // cout << list1 << endl;

    // DoublyLL list2;
    // list2.insert(5);
    // list2.insert(6);
    // list2.insertAtHead(7);
    // list2.insertAtHead(8);
    // list2.insertAtHead(9);

    // list1.Swap(list2);

    // cout << "List1: " << list1 << endl << "List2: " << list2 << endl;

    // DoublyLL list(list1);
    // list1.insertAtHead(10); 
    // cout << "Values of list1 copied into list using copy constructor! \n" << list << endl;

    // DoublyLL assignmentList1, assignmentList2;
    // assignmentList1 = assignmentList2 = list1;

    // list2.insertAtHead(20);

    // cout << "Values of list2 copied into assignmentList1 & assignmentList2 using Assignment operator! \n" << assignmentList1 << endl << assignmentList2;
}
Insert at the Head & Tail
Insert at any Position
Delete at any Position

Last updated

Was this helpful?