I played an demo about a strategic game. It is so vivid. That is implemented in Javascript. Web game will
become a fashion in the future.
I need a good rest for long, although I am going to learn javascritpt.
//GList.cpp
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
template <class T>
class List {
struct _Node {
T val;
struct _Node *prev;
struct _Node *next;
};
private:
int _node_num;
struct _Node *_head;
struct _Node *_tail;
struct _Node *_current;
public:
List() : _node_num(0), _head(NULL), _tail(NULL), _current(NULL) {
}
void add(T val) {
struct _Node *p = NULL;
p = (struct _Node *)malloc(sizeof(struct _Node));
if (p) {
p->next = NULL;
p->prev = NULL;
if (!_head) {
_head = p;
_tail = p;
}
else {
_tail->next = p;
p->prev = _tail;
_tail = p;
}
p->val = val;
_node_num++;
}
}
inline bool isEmpty() {
return (!_head) ? true : false;
}
T begin() {
_current = _head;
return _head->val;
}
bool hasMore() {
return (_current->next) ? true : false;
}
T next() {
_current = _current->next;
return _current->val;
}
~List() {
struct _Node *p = NULL;
for (p = _head; p; p = _head) {
_head = p->next;
free(p);
}
_node_num = 0;
_head = NULL;
_tail = NULL;
_current = NULL;
}
};
int main() {
List<int> listInt;
for (int i = 0; i < 10; i++)
listInt.add(i);
if (!listInt.isEmpty()){
cout<<listInt.begin()<<endl;
while(listInt.hasMore())
cout<<listInt.next()<<endl;
}
return 0;
}