简体   繁体   English

严重错误:ll.h:无此类文件或目录

[英]fatal error: ll.h:No such file or directory

I have two files ll.cpp and ll.h both in the same directory. 我在同一目录中有两个文件ll.cpp和ll.h。

ll.cpp ll.cpp

  #include <ll.h>

#include <iostream>

using namespace std;




    template <class t>
    LinkedL<t>::LinkedL()
     {
        flag=0;
        head=NULL;
        tail=NULL;
        curr=0;
    }
    template <class t>
    LinkedL<t>::void insertS(t inf)
    {
        Node<t> *n=new Node<t>;
        n->next=head;
        n->data=inf;
        head=n;
        if(curr==0)
            tail=n;
        curr++;
        //cout<<curr<<"\n";
    }
    template <class t>
    LinkedL<t>::void insertE(t inf)
    {
        Node<t> *n=new Node<t>;
        n->next=NULL;
        n->data=inf;
        if(curr!=0)
        tail->next=n;
        tail=n;
        if(curr==0)
            head=n;
        curr++;
        //cout<<curr<<"\n";
    }
    template <class t>
    LinkedL<t>::t delS()
    {
        if(curr>=1)
        {
            flag=1;
            t temp=head->data;
            Node<t> *n=head;
            head=head->next;
            if(head==NULL)
                tail=NULL;
            delete n;
            curr--;
            return temp;
        }
        else
        {
            cout<<"EMPTY LIST\n";
        }
    }
    template <class t>
    LinkedL<t>::t delE()
    {

        if(curr>=1)
        {
            flag=1;
            Node<t> *n=head;
            t temp;
            if(curr>1)
            {
                while(n->next!=tail)
                    {   
                        //cout<<n->data<<" ";
                        n=n->next;
                    }
                    //cout<<"\n";
                Node<t> *n1=tail;
                temp=n1->data;
                tail=n;
                tail->next=NULL;
                //cout<<n->data<<"\n";
                delete n1;
                }
                else if(curr==1)
                {
                    temp=tail->data;
                    delete tail;
                    head=NULL;
                    tail=NULL;
                }

                curr--;
                //cout<<curr<<"\n";
                return temp;
        }else if(curr==0)
        {
            cout<<"EMPTY LIST\n";
        }

    }
    template <class t>
    LinkedL<t>::bool search(t inf)
    {
        Node<t> *n=head;
        while(n!=NULL && n->data!=inf)
            n=n->next;
        if(n==NULL)
            return false;
        return true;
    }
    template <class t>
    LinkedL<t>::void traverse()
    {
        if(curr!=0)
        {
            Node<t> *n=head;
            while(n!=NULL)
                {
                cout<<n->data<<" ";
                n=n->next;
                }
            cout<<'\n';
        }
        else
        {
            cout<<"EMPTY\n";
        }
    }
    template <class t>
    LinkedL<t>::bool isEmpty()
    {
        if(curr==0)
            return true;
        return false;
    }
    template <class t>
    LinkedL<t>::t at(int i)
    {
        if(i<=curr)
        {
            flag=1;
            Node<t> *n=head;
            int k=1;
            while(k!=i)
            {
                n=n->next;
                k++;
            }
            return n->data;
        }
        else
            cout<<"Invalid Index\n";
    }
    template <class t>
    LinkedL<t>::void insert(int i,t dat)
    {
        if(i<=curr+1)
        {
            flag=1;
            if(curr==0 || i==1)
            {
                insertS(dat);
            }
            else
            {
                Node<t> *n1=NULL;
                Node<t> *n=head;
                int k=1;
                while(k!=i)
                {
                    n1=n;
                    n=n->next;
                    k++;
                }
                Node<t> *temp=new Node<t>;
                temp->next=n;
                n1->next=temp;
                temp->data=dat;
                curr++;
            }
        }
        else
            cout<<"Invalid Index\n";
    }
    template <class t>
    LinkedL<t>::void reverse()
    {
        if(curr!=0)
        {
            Node<t> *n=head;
            Node<t> *n1=head;
            Node<t> *n2=NULL;
            while(n!=NULL)
            {
                n1=n->next;
                n->next=n2;
                n2=n;
                n=n1;
            }
            n=head;
            head=tail;
            tail=n;
        }
    }
    template <class t>
    LinkedL<t>::t delet(int i)
    {
        Node<t> *n=head;
        if(head!=NULL && i<=curr)
        {
            flag=1;
            t dat;
            int k=1;
            if(i==1)
                dat=delS();
            else
            {
                while(k!=i-1)
                    {
                        n=n->next;
                        k++;
                    }
                Node<t> *n1=n->next;
                n->next=n->next->next;
                dat=n1->data;
                delete n1;
            }
            curr--;
            return dat;
        }
        else
        {
            cout<<"Invalid Index\n";
        }
    }

ll.h ll.h

   #ifndef LL_H
#define LL_H

template <class t>
class Node
{
    public:
    Node<t> * next;
    t data;
};


template <class t>
class LinkedL
{
    private:
        Node<t>* head;
        Node<t>* tail;
        int curr;
    public:
     int flag; 
     LinkedL();

    void insertS(t inf);

    void insertE(t inf);

    t delS();

    t delE();

    bool search(t inf);

    void traverse();


    bool isEmpty();

    t at(int i);

    void insert(int i,t dat);

    void reverse();

    t delet(int i);


};
#endif

I am not able to figure out why the compiler is giving this error. 我无法弄清楚为什么编译器会给出此错误。 Same thing is happening for all the .h and .cpp pairs as a crosscheck I changed the permission to rwx for all users but still the same error is coming. 作为交叉检查,所有.h和.cpp对都发生了相同的事情,我将所有用户的权限更改为rwx,但仍会出现相同的错误。 Please help. 请帮忙。

If you include something and write it with <> the preprocessor is searching in external libraries like the std library. 如果包含某些内容并用<>编写,则预处理器将在外部库(例如std库)中进行搜索。 Similar to what you did here: 与您在此处执行的操作类似:

#include <iostream>

But if you include your own .cpp or .h files use "" so it will search in your local directory. 但是,如果您包括自己的.cpp.h文件,请使用""这样它将在您的本地目录中搜索。 Therefore, use in this case: 因此,在这种情况下使用:

#include "ll.h"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM