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 - LinkStack.h

#include "TreeNode.h"

#ifndef _LINKSTACK_H
#define _LINKSTACK_H

class LinkNode{
public:
TreeNode* treenode;
LinkNode* next;
LinkNode(TreeNode* thenode){
treenode=thenode;
next=NULL;
}
};

class LinkStack{
public:
LinkNode* head;
LinkStack(){ head=NULL; }

~LinkStack(){
deletenode(head);
}

void deletenode(LinkNode *n){
if(n==NULL) return;
deletenode(n->next);
delete n;
}

BOOL isEmpty() { return (head==NULL); }

void push(TreeNode* thenode){
LinkNode* newnode = new LinkNode(thenode);
if(isEmpty()){
head=newnode;
}
else{
newnode->next=head;
head=newnode;
}
}

UINT NumOfNodes(){
LinkNode* curr;
curr=head;
UINT temp;
temp=0;
while(curr!=NULL){
temp++;
curr=curr->next;
}

return temp;
}

LinkNode* getNode(int nodeno){
int i;
LinkNode* curr;
curr=head;
i=0;
while(i<nodeno){
curr=curr->next;
i++;
}

return curr;
}

LinkNode* pop(){
LinkNode* temp;
temp=head;
head=head->next;
return temp;
}

void reset(){
if(head==NULL) return;
deletenode(head);
head=NULL;
}
};

#endif

No comments: