new_temp->pre=Con->p; Con->p->next=new_temp; Con->p=Con->p->next; Con->p->next=NULL; }
时间: 2023-08-07 09:56:51 浏览: 55
这段代码的作用是将一个新节点 `new_temp` 插入到链表中 `Con` 指针所指向的节点之后,并将 `Con` 指针移动到新插入的节点上。具体步骤如下:
1. 将 `new_temp` 的 `pre` 指针指向 `Con` 指针所指向的节点。
2. 将 `Con` 指针所指向的节点的 `next` 指针指向 `new_temp`。
3. 将 `Con` 指针移动到新插入的节点上,即 `Con->p = Con->p->next`。
4. 将新插入的节点的 `next` 指针设为 `NULL`,表示该节点为链表的最后一个节点。
请注意,这段代码中的变量和结构体定义没有提供,因此无法判断具体的数据类型和上下文。如果有需要,请补充相关代码。
相关问题
PP->error_current = PP->Set_temperature - current_temp
根据引用\[1\]中的代码,PP->error_current的计算公式为PP->Set_temperature - current_temp。
#### 引用[.reference_title]
- *1* *2* *3* [Linux thermal简述](https://blog.csdn.net/m0_73052512/article/details/131626750)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
bool ff(int number,int size)//首次适应算法 { pNod temp= new Free_Node; Free_Node *p=headNode->next; //从首节点开始 temp->date.number=number; temp->date.size=size; temp->date.flag=BUSY; while(p) { if (p->date.flag==FREE && p->date.size == size )//请求大小刚好满足 { p->date.flag=BUSY; p->date.number=number; return true; } if (p->date.flag==FREE && p->date.size>size)//说明还有其他的空闲区间 { temp->next=p; temp->prior=p->prior; temp->date.begin_address=p->date.begin_address; p->prior->next=temp; p->prior=temp; p->date.begin_address=temp->date.begin_address+temp->date.size;//空闲分区开始地址+此次分配的空间 p->date.size-=size; //分配空闲作业 return true; } p=p->next; } return false; }改为最差适应算法
将该函数改为最差适应算法的代码如下所示:
```
bool wf(int number, int size) {
Free_Node* temp = new Free_Node;
Free_Node* p = headNode->next;
Free_Node* worst_node = nullptr; // 最差适应算法需要记录最大空闲区间
int max_size = -1; // 最差适应算法需要记录最大空闲区间的大小
temp->date.number = number;
temp->date.size = size;
temp->date.flag = BUSY;
while (p) {
if (p->date.flag == FREE && p->date.size >= size) { // 如果空闲区间大小满足要求
if (p->date.size > max_size) { // 找到更大的空闲区间
max_size = p->date.size;
worst_node = p;
}
}
p = p->next;
}
if (worst_node) { // 找到了空闲区间
temp->next = worst_node;
temp->prior = worst_node->prior;
temp->date.begin_address = worst_node->date.begin_address;
worst_node->prior->next = temp;
worst_node->prior = temp;
worst_node->date.begin_address = temp->date.begin_address + temp->date.size;
worst_node->date.size -= size;
worst_node->date.flag = FREE;
return true;
}
return false;
}
```
需要注意的是,最差适应算法需要记录最大空闲区间,因此在遍历空闲区间时需要记录当前的最大空闲区间。