gpt4 book ai didi

C++:从链表中提取值

转载 作者:行者123 更新时间:2023-11-28 00:50:34 26 4
gpt4 key购买 nike

<分区>

当我调用 extractMin() 时这段代码崩溃了不止一次。我认为这应该是显而易见的你们中的一些人问题出在函数上,因为我是指针的新手,可能是一个明显的错误。所以你知道它是一个链表就足够了,除了函数应该使用 < 来检索字典序最小值之外,无需详细说明。运算符,然后从链表中删除该值。

string LinkedListPQueue::extractMin() {
if (this->isEmpty()) throw ErrorException("Empty queue.");
string front = LEX_HIGH;
cell *old;

for (int i = 0; i < this->size(); i++) {
if (this->head->value < front) {
front = this->head->value;
old = this->head;
}

old = this->head;
this->head = this->head->next;
}

logSize--;
delete old;
return front;
}



void LinkedListPQueue::enqueue(const string& elem) {
cell *newCell = new cell;
newCell->value = elem;
newCell->next = NULL;
if(this->isEmpty()) {
this->head = this->tail = newCell;
logSize++;

} else {
recurSort(newCell);
this->tail->next = newCell;
this->tail = newCell;
logSize++;
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com