📄 dllist-driver.cc
字号:
#include "dllist.h"
#include <iostream>
#include "system.h"
//extern int testnum;
//extern Thread *currenThread;
extern int testnum;
void ListInsert(int N, DLList *List)
{
// extern int testnum;
// extern Thread *currentThread;
int d[2] = {1, -1};
int sortkey = 0;
for (int i = 0; i != N; ++i)
{
int *p = new int;
*p = i;
// switch (i%3)
// {
/* case 0: if (testnum == 2 || testnum == 4)currentThread->Yield();
else
if (testnum == 5) List->SortedInsert(p,100);
else List->Prepend(p);
std::cout << "the insert item is " << *p << std::endl; break;
case 1: if(testnum == 2 || testnum == 4) currentThread->Yield();
List->Append(p);std::cout << "the insert item is "
<< *p << std::endl; break;*/
// case 2:// if (testnum == 5) sortkey = 100;
if (testnum == 2)currentThread->Yield();
sortkey = sortkey + d[i%2]*i*5;
List->SortedInsert(p,sortkey);std::cout << "the insert item and its Key are "
<< *p << " and " << sortkey << std::endl;
// }
//p = NULL;
}
}
void ListRemove(int N, DLList *List)
{
//if (!(List->IsEmpty()))
// extern Thread *currentThread;
// extern int testnum;
int i = 0;
while ((!(List->IsEmpty())) && (i != N))
{
int *key = new int;
void *item = NULL;
if (testnum == 4) {currentThread->Yield(); item = List->SortedRemove(0);currentThread->Yield();*key = 0;}
item = List->Remove(key);
if (item == NULL) std::cout << "remove error" << std::endl;
else
std::cout << "the removed item and its key are " << *((int *)item) << " and " << *key << "\n" << std::flush;
delete key;
++i;
}
//}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -