本文整理汇总了C++中Struct::add方法的典型用法代码示例。如果您正苦于以下问题:C++ Struct::add方法的具体用法?C++ Struct::add怎么用?C++ Struct::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Struct
的用法示例。
在下文中一共展示了Struct::add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: start
void start() {
int number(1);
Struct *head = new Struct();
Struct *temp;
cout << "Start X : ";
cin >> head->x;
cout << "Start Y : ";
cin >> head->y;
head->next = NULL;
horse->path[head->x][head->y] = number++;
horse->mark[head->x][head->y] = 0;
while (number <= (SIZE * SIZE)) {
if (number == (SIZE * SIZE)) { //最后一步单独处理
for (int i(0);i < SIZE;i++) {
for (int j(0);j < SIZE;j++) {
if (horse->mark[i][j] == 1) {
head = head->add(i, j, head, 0);
horse->path[i][j] = number++;
horse->mark[i][j] = 0;
break;
}
}
}
continue;
}
horse->init(); //初始化权值表
horse->updateWeight(head->x, head->y); //更新这一点的权值表
if (flag) {
horse->weight[temp->key] == SIZE + 1;
}
int key = horse->findSmall(); //找到权值最小的点
if (key == -1 && number != (SIZE * SIZE + 1)) {
horse->mark[head->x][head->y] == 1;
horse->path[head->x][head->y] == 0;
number--;
temp = head;
head = head->remove(head);
flag = true;
continue;
}
x = head->x;
y = head->y;
getXY(key); //得到该点对应的坐标
head = head->add(x, y, head, key); //将新走的位置坐标插入链表
// cout << head->x << " , " << head->y << " " << number << endl;
horse->path[head->x][head->y] = number++;
horse->mark[head->x][head->y] = 0; //标记为已走过
}
print();
}