这个c ++链表代码有什么问题?

Zah*_*ema -11 c++

我正在研究C++控制台应用程序课程

我试图创建一个链表

视觉工作室只给了我30多个错误,虽然代码看起来对我很好

什么是实际错误? 在此输入图像描述

 #include <iostream>

using namespace std;

template <class Nodetype>
class Node{
private:
    Nodetype data;
    Node<Nodetype>*next;
    friend Linkedlist ;
};

template <class Nodetype>
class Linkedlist{
private:
    Node<Nodetype>*head;
public:
    Linkedlist();
    void insertItem(Nodetype item);
    void DeleteItem(Nodetype item);
    void MakeEmpty();
    bool FindItem(Nodetype item);
    void Display();
};
template <class Nodetype>
Linkedlist<Nodetype>::Linkedlist()
{
    head = NULL;
}

template <class Nodetype>
void Linkedlist< Nodetype >::insertItem(Nodetype item)
{
    Node< Nodetype > *location;
    location = new Node< Nodetype >();
    location->data = item;
    location->next = head;
    head = location;
}

template <class Nodetype>
void Linkedlist<Nodetype>::Display()
{
    Node<Nodetype>*current = head;
    while (current != NULL)
    {
        cout << current->data;
        current = current->next;
    }
}

template <class Nodetype>
void Linkedlist< Nodetype >::DeleteItem(Nodetype item)
{
    Node< Nodetype >* preLocation = NULL;
    Node< Nodetype >* location = head;
    if (item == location->data)
        head = location->next;
    else
    {
        do
        {
            preLocation = location;
            location = location->next;
        } while (item != location->data);
        preLocation->next = location->next;
    }
    delete location;
}

template <class Nodetype>
void Linkedlist<Nodetype>::MakeEmpty()
{
    Node<Nodetype>* tempPtr;
    while (head != NULL)
    {
        tempPtr = head;
        head = head > next;
        delete tempPtr;
    }
}

template <class Nodetype>
bool Linkedlist<Nodetype>::FindItem(Nodetype item)
{
    bool found;
    Node<Nodetype> *currentPos = head;
    found = false;
    while ((currentPos != NULL) && !found)
    {
        if (item == (currentPos->data))
            found = true;
        else
            currentPos = currentPos->next;
    }
    return found;
}

void main(){
    int x = 0;
    Linkedlist<string> L;
    L.insertItem("name1");
    L.insertItem("name2");


    cin >> x;
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*ely 5

视觉工作室只给了我30多个错误,虽然代码看起来对我很好

这不好,它充满了错误.

听听你的编译器.转到它告诉您有错误的行.修复它们.

例如:

     head = head > next;
Run Code Online (Sandbox Code Playgroud)

这显然是错的.修理它.

这不是有效的C++:

friend Linkedlist ;
Run Code Online (Sandbox Code Playgroud)

它应该是:

template<class T> friend class LinkedList;
Run Code Online (Sandbox Code Playgroud)

LinkedList在你说它是朋友之前,你应先申报.