왜 하나의 함수가 작동하지 않는 지 알 수 없습니다. 그것은 const 포인터와 관련이 있습니다.const 포인터로 이중 링크 된 목록 인쇄
//prints the contents of the list interval [begin,end)
//to the output stream os; values should be separated by spaces
void print(const Node* begin, const Node* end, ostream& os)
{
Node* current_node = begin;
do
{
os << current_node->value << " ";
current_node = current_node->next;
}
while(current_node != end);
os << endl;
}
이 기능의 헤드를 변경할 수 없습니다.
이 기능이 작동합니까?
//erases the list interval [begin,end)
//attention: this should not erase 'end', see remarks above
void erase(Node* begin, Node* end){
Node* current_node = begin;
Node* next_node = begin->next;
Node* begin_node = begin->prev;
while(current_node != end){
next_node->prev = current_node->prev;
begin_node->next = next_node;
delete current_node;
current_node = next_node;
next_node = current_node->next;
}
}
그리고 여기가 바로 노드
struct Node
{
int value;
struct Node* next;
struct Node* prev;
};
그리고 실제로 문제가 있습니까? 컴파일러 오류, 런타임 오류, 예기치 않은 결과가 있습니까? 귀하의 질문은 명확하지 않습니다. –