CORE SOURCE CODE solving 8 Puzzle AI problems written in MS Visual MFC C++.

COMPLETE Full set of working SOURCE CODE for the working MFC C++ program, SPEED UP your learning process,
just 4.99 USD. Email / Paypal to ahyeek@gmail.com

Full working program can be downloaded to TRY out: AI 8-puzzle (8 Puzzle) solver

Friday, May 9, 2008

8 Puzzle Code - Queue.cpp

#include "stdafx.h"
#include "queue.h"

Queue::Queue(){
head=NULL;
tail=NULL;
}

BOOL Queue::isEmpty(){

return (head==NULL && tail==NULL);

}



void Queue::add(char* p, char* pp){

StateNode* newnode = new StateNode();
newnode->setPuzzle(p);
newnode->setParentState(pp);

if(isEmpty()){
head=newnode;
tail=head;
}
else{
tail->next=newnode;
tail=newnode;
}
}

StateNode* Queue::get(){
StateNode* temp;
temp=head;
head=head->next;
if(head==NULL) tail=NULL;
return temp;
}

void Queue::deleteNode(StateNode* n){
StateNode* curr=head;
while(curr!=NULL){
head=head->next;
delete curr;
curr=head;
}
}

Queue::~Queue(){
TRACE(_T("Delete Q...\n"));
deleteNode(head);
}

No comments: