c++ - creating doubly linked list -
i want create doubly linked list , check if empty. please tell mistake. error shown : in function empty(), head , tail out of scope. didn't work when define 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;} }
i think need include empty method in class:
bool dict::empty() { return head->next==tail; }
Comments
Post a Comment