Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // node.cpp
- // EightPuzzle
- //
- // Created by 李依蓉 on 2020/3/19.
- // Copyright © 2020 李依蓉. All rights reserved.
- //
- #include <stdio.h>
- #include <iostream>
- #include "node.h"
- using namespace std;
- void Node::displayNodeStatus()
- {
- for(int i = 0; i < 9; i++)
- {
- cout << this->status[i] << "," ;
- }
- cout << endl;
- }
- void Fringe::InsertNode(Node x)
- {
- int status_temp[9];
- for(int i = 0; i < 9; i++)
- status_temp[i] = x.status[i];
- Node *newNode = new Node(status_temp); // 配置新的記憶體
- if (first == NULL) { // 若list沒有node, 令newNode為first
- first = newNode;
- return;
- }
- Node *current = first;
- while (current->child != 0) { // Traversal
- current = current->child;
- }
- current->child = newNode; // 將newNode接在list的尾巴
- }
- void Fringe::PrintFringe()
- {
- if (first == NULL) { // 如果first node指向NULL, 表示list沒有資料
- cout << "List is empty.\n";
- return;
- }
- Node *current = first; // 用pointer *current在list中移動
- while (current != NULL) { // Traversal
- for(int i = 0; i < 9; i++)
- cout << current->status[i] << ",";
- cout << endl;
- current = current->child;
- }
- cout << endl;
- }
- void Node::getStatus(int (&arr)[9])
- {
- copy(begin(this->status), end(this->status), begin(arr));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement