对于家庭作业,我需要删除该数字传入的所有类似节点。例如,如果我在列表中
3 5 5 4
5's 将从链表中删除,我将以
3 4
我们不允许使用这个类的标准库,这是头文件
namespace list_1
{
class list
{
public:
// CONSTRUCTOR
list( );
// postcondition: all nodes in the list are destroyed.
~list();
// MODIFICATION MEMBER FUNCTIONS
//postcondition: entry is added to the front of the list
void insert_front(const int& entry);
//postcondition: entry is added to the back of the list
void add_back(const int& entry);
// postcondition: all nodes with data == entry are removed from the list
void remove_all(const int& entry);
// postcondition: an iterator is created pointing to the head of the list
Iterator begin(void);
// CONSTANT MEMBER FUNCTIONS
// postcondition: the size of the list is returned
int size( ) const;
private:
Node* head;
};
}
我可以理解如何删除列表的前面和后面。但是由于某种原因,我无法绕过列表并删除所有传入的数字。任何有帮助!谢谢
编辑以包含 Node.h
#pragma once
namespace list_1
{
struct Node
{
int data;
Node *next;
// Constructor
// Postcondition:
Node (int d);
};
}