Я ищу общие советы и помощь в написании кода с моим двусвязным списком.Буду очень признателен за любые исправления кодирования с комментариями.
Я довольно незнаком с использованием указателей и действительно нуждаюсь в некоторой помощи.
#pragma once
#ifndef LIST_H
#define LIST_H
#include <cstddef>
template <class Type>
class List
{
public:
//constructor of List class
List()
{
//Head and Tail are assigned Null values when the Object is constructed in Memory
Head = nullptr;
Tail = nullptr;
}
~List()
{
}
{
NODE *current = new NODE();
current->Data = Data;
if (Head == NULL)
{
Head = current;
Tail = current;
}
else
{
Tail->next = current;
current->previous = Tail;
Tail = current;
}
}
void find(Type Value)
{
NODE * current = Head;
while (current != nullptr && current->Data != Value)
{
current = current->next;
}
}
void Delete(Type value)
{
NODE * Delete_Node = find(value);
if (*Head == Delete_Node)
{
Delete_Node->next->previous = nullptr;
Head = Delete_Node->next;
}
else if (*Tail == Delete_Node)
{
Delete_Node->previous->next = nullptr;
Tail = Delete_Node->previous;
}
else if (*Tail == Delete_Node && *Head == Delete_Node)
{
Head = nullptr;
Tail = nullptr;
}
else
{
Delete_Node->next->previous = Delete_Node->previous;
Delete_Node->previous->next = Delete_Node->next;
}
delete Delete_Node;
}
void display() {
NODE* pointer;
pointer = Head;
while (pointer != nullptr)
{
std::cout << pointer->Data << " ";
pointer = pointer->next;
}
}
private:
struct NODE
{
Type Data;
NODE *next;
NODE *previous;
NODE()
{
Data = NULL;
next = nullptr;
previous = nullptr;
}
};
NODE* Head;
NODE* Tail;
};
#endif
основной файл.
#include "List.h"
#include <iostream>
int main()
{
List<int> My_List;
My_List.Insert(1);
My_List.Insert(2);
My_List.Insert(3);
My_List.Insert(4);
My_List.display();
My_List.Delete(3);
My_List.display();
My_List.Delete(4);
My_List.display();
My_List.Delete(1);
My_List.display();
My_List.Delete(2);
}
Я проверяю функции вставки и удаления.Я не уверен, где кодирование неверно.Это ошибки, которые я получаю.
Error C2678 binary '==': no operator found which takes a left-hand operand of type 'List<int>::NODE' (or there is no acceptable conversion) list.h 66
Error C2440 'initializing': cannot convert from 'void' to 'List<int>::NODE *' list.h 55
Error C2678 binary '==': no operator found which takes a left-hand operand of type 'List<int>::NODE' (or there is no acceptable conversion) list.h 56
Error C2678 binary '==': no operator found which takes a left-hand operand of type 'List<int>::NODE' (or there is no acceptable conversion) list.h 61