基本的には、リンクリストを使用してキューを実装し、1日の間に店に並んでいる人をシミュレートし、前の人が仕事を終えるまで待ちます。最初の数人は問題なく通過しますが、デキューの2番目の呼び出しに到達すると、segfaultが発生します。gdbデバッガーは、エラーはこの行から発生すると言いますhead = current-> next; (ここで、current = head)。
これが私のデキュー機能です:
void BankQueue::dequeue()
{
Node* current=head;
head=current->next;
if(head!=NULL)
{
head->prev=NULL;
}
delete current;
}
エンキュー関数は次のとおりです(エンキュー時にメモリリークが発生した場合):
void BankQueue::enqueue(Customer s)
{
Node* node= new node;
node->data=s;
node->next=NULL;
if(tail==NULL)
{
head=node;
tail=node;
node->prev=NULL;
}
else
{
node->prev=tail;
tail->next=node;;
tail=node;
}
事前のおかげで、セグメンテーション違反が発生する可能性のある場所に関して皆さんが提供できる支援は素晴らしいでしょう。
PSIは、必要に応じてより多くの情報を提供できます。