Q:

How to display a message saying doubly linked list is empty,cannot delete element from it?

I have implemented a sorted doubly linked list with the help of pointers in C++.I want to display an error message on deleting the last element saying "doubly linked list is empty cannot delete any more elements" and also display a message before deleting the last element saying"the last element in the node are you sure you want to delete it"?
#include "stdafx.h"
#include "DoublyLinkedList.h"

#include<iostream>
using namespace std;

DoublyLinkedList::DoublyLinkedList():Head(nullptr),Tail(nullptr) {

}

DoublyLinkedList::~DoublyLinkedList() {

    Node *current = Head;
    while (current != NULL)
    {
    Node* next = current->Next;   //The objects pointed to by head and tail at the beginning of the destructor are deleted         
        Node* prev = current->Prev;     //  through the current pointer. Then they are deleted again at the                                                               end of the destructor.
        delete current;
        current = next;
        current = prev;
    }

}
void DoublyLinkedList::SortedInsert(const int& new_element) {

    if(new_element !=0){
        Node* np = new Node(new_element);
    if (!Head)
    {
        Head = np;
        Tail = np;
    }
    else if (new_element < Head->Element)
    {
        np->Next = Head;
        Head->Prev = np;
        Head = np;
    }
    else
    {
        Node *cur = Head->Next;
        while ((cur) && (new_element >= cur->Element))
            cur = cur->Next;

        if (cur)
        {
            np->Prev = cur->Prev;
            np->Next = cur;
            cur->Prev->Next = np;
            cur->Prev = np;
        }
        else
        {
            Tail->Next = np;
            np->Prev = Tail;
            Tail = np;
        }
        }
    }
}

void DoublyLinkedList::Delete(const int& del_element)
{
    Node *cur = Head;
    while (cur)
    {
        if (cur->Element == del_element)
        {
            if (cur->Prev)
                cur->Prev->Next = cur->Next;
            if (cur->Next)
                cur->Next->Prev = cur->Prev;
            if (cur == Head)
                Head = cur->Next;
            if (cur == Tail)
                Tail = cur->Prev;
            delete cur;
            break;
        }
        cur = cur->Next;

    }
}

void DoublyLinkedList::traverse_head() {
    Node *t = Head;
    while (t != NULL)
    {
        cout << t->Element << "\t";

        t = t->Next;
    }

    cout << endl;
}

void DoublyLinkedList::traverse_tail() {

    Node *temp = Tail;
    while (temp != NULL) {
        cout << temp->Element << "\t";
        temp = temp->Prev;
    }
}
main.cpp

// Question1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include"DoublyLinkedList.h"
#include<iostream>

using namespace std;

    int main()
    {

        DoublyLinkedList intlist;

        int i = 0, x=0,delete_elm=0;

        //intlist.SortedInsert(3);
        //intlist.SortedInsert(6);
        //intlist.SortedInsert(7);
        //intlist.SortedInsert(10);
        //intlist.SortedInsert(-1);

        //intlist.traverse_head();

        do
        {
            cout << "\nEnter value of node.Press 0 to stop\n";
            cin >> x;

            if ((!cin) || cin.peek() != '\n') {

                cin.clear();
                    cin.ignore(numeric_limits<streamsize>::max(), '\n');
                    cout << "Invalid input, no string allowed!!" << endl;
            }
            else {
                intlist.SortedInsert(x);
                i++;
            }
        } while (x != 0);
        intlist.traverse_head();

        cout << "\nTraversing Doubly Linked List head first\n";
        intlist.traverse_head();
        cout << "\nTraversing Doubly Linked List tail first\n";
        intlist.traverse_tail();
        cout << endl;
        do {
            cout << "Which element do you want to delete? 0 to stop delete operation" << endl;
            cin >> delete_elm;
            cout << endl;
            if ((!cin) || cin.peek() != '\n' || x < 0) {

                cin.clear();
                cin.ignore(numeric_limits<streamsize>::max(), '\n');
                cout << "Invalid input, no string allowed!!" << endl;
            }
            else {

                intlist.Delete(delete_elm);
                cout << "\nTraversing Doubly Linked List head first\n";
                intlist.traverse_head();
                cout << "\nTraversing Doubly Linked List tail first\n";
                intlist.traverse_tail();
                cout << endl;
            }
        } while (delete_elm != 0);

        system("pause");
        return 0;
    }

A:

Since you seem to not be using dummy nodes, checking if the list is empty is the same as checking if the Head or Tail pointers are null. Checking if it's only one element is the same as checking if Head->Next is null (be sure to check that Head is not null first, of course).
Alternatively, you can maintain a size variable (incremented in insert and decremented in remove) or write a method to calculate the size by traversing the list.

