그래서 연결된 목록을 사용하는 프로젝트에서 작업하고 있습니다. 이 프로그램은 기본적으로 -999가 입력 될 때까지 숫자를 취한 다음 작업을 수행합니다. 문제가있는 두 가지 작업은 deleteAll입니다. 여기서 모든 값은 목록에서 삭제되고 deleteSmallest는 목록에서 가장 작은 값이 삭제됩니다. 다음과 같이 두 함수를 호출하는 코드는 다음과 같습니다코드에서 오류를 해결하고 오류 메시지를 해석하는 방법
int num;
cout << "Enter a number you would like deleted from the whole list: ";
cin >> num;
uList.deleteAll(num);
cout << "New list: " << uList << endl;
uList.deleteSmallest();
cout << "After deleting the smallest number, the list now is: " << uList << endl;
다음과 같이 deleteAll에 대한 코드는 다음과 같습니다
이template <class Type>
void UnorderedLinkedList<Type>::deleteAll(const Type& deleteItem)
{
NodeType<Type>* curr;
NodeType<Type>* p = NULL;
NodeType<Type>* q = NULL;
curr = first;
if(first == NULL)
throw std::runtime_error("Cannot delete from an empty list");
else
{
for(int i = 0; i < count; i++)
{
if(curr->info == deleteItem)
{
p = curr;
q = p->link;
p->link = q->link;
delete q;
}
curr = curr->link;
}
}
delete p;
delete curr;
}
deleteSmallest에 대한 코드는 다음과 같다 :
template <class Type>
void UnorderedLinkedList<Type>::deleteSmallest()
{
NodeType<Type>* curr;
NodeType<Type>* p;
NodeType<Type>* q;
NodeType<Type>* r;
curr = first;
if (first == NULL)
throw std::runtime_error("Cannot delete from an empty list");
else
{
for(int i = 0; i < count; i++)
{
if(curr->link->info < curr->info)
{
int smallest = curr->link->info;
p = curr;
q = curr->link;
}
curr = curr->link;
}
}
r = q->link;
p->link = q->link;
delete q;
}
오류가 나는 :
1 [main] Project 5 4044 cygwin_exception::open_stackdumpfile: Dumping stack trace to Project 5.exe.stackdump
큰 질문을 게시하는 것을 유감스럽게 생각하지만 누군가이 상황에서 오류의 의미를 설명 할 수 있습니까? 고맙습니다! deleteAll()
를 들어
이중 삭제를 당신의'deleteAll'의 맨 아래에있는 항목은 현재 항목이 * 일치하지 않을 때 else-handlng 경우 (또는없는 부분)와 같이 매우 의심 스럽습니다. – WhozCraig