当我运行此代码时,输出是“添加了一些东西”,然后是无限循环......
我的程序应该打印:
添加了一些东西
打印的东西我不明白为什么程序无法在循环中退出
var currentDate = new Date();
var weekday = ['Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat'];
var day = weekday[currentDate.getDay()];
console.log(day);
我正在寻找解决方案和解释
非常感谢
答案 0 :(得分:-1)
为了使线程能够安全地进行通信和共享数据,必须正确地同步它们。在您的示例中,最简单的方法是将列表包装在同步包装器中:
void appendNode(Node **root, Node** lastNode, Node *curr) {
if (!*root) { // root not yet assigned?
*root = curr;
*lastNode = curr;
} else {
(*lastNode)->next = curr; // append curr after lastNode
*lastNode = curr; // let curr become the lastNode
}
(*lastNode)->next = NULL; // terminate the list at lastNode
}
Node* removeOddValues(Node **source)
{
Node *curr = *source;
Node *evenRoot = NULL;
Node *oddRoot = NULL;
Node *evenLast = NULL;
Node *oddLast = NULL;
while(curr)
{
Node *next = curr->next;
if(curr->data % 2!=0) {
appendNode(&oddRoot, &oddLast, curr);
}
else {
appendNode(&evenRoot, &evenLast, curr);
}
curr = next;
}
*source= evenRoot;
return oddRoot;
}