creating doubly linked list

Nikhil Chilwant

I want to just create the doubly linked list and check if it is empty. Please tell the mistake. ERROR shown is : In function empty(), head and tail are out of scope. Didn't work when define as struct in class Dict.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class node
{   public:
    string data;
    node* next;
    node* prev;
    friend class Dict;
};

class Dict
{   public:
    bool empty();
    Dict();
    node* head;
    node* tail;

};

Dict::Dict()
{   head=new node;
    tail= new node;
    head->next=tail;
    tail->prev=head;

}

bool empty()
{
    return head->next==tail;
}

int main()
{
    Dict my_list;
    if(my_list.empty())
        {cout<<"empty list"<<endl;}
    else
        {cout<<"Not empty"<<endl;}
}
McKay

I think you just need to include the empty method in your class:

bool Dict::empty()
{
    return head->next==tail;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related