/*
* Queue.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
#pragma once
#include <sol\Collection.h>
#include <sol\ListEntry.h>
namespace SOL {
class Queue :public Collection {
private:
ListEntry* head;
ListEntry* tail;
public:
Queue()
:head(NULL), tail(NULL)
{
}
public:
~Queue()
{
//Pending
}
public:
void addLast(Object* obj)
{
ListEntry* ent = new ListEntry(obj);
if(head == NULL) {
head = ent;
tail = ent;
return;
}
if(tail) {
tail -> setNext(ent);
tail = ent;
}
}
public:
void addFirst(Object* obj)
{
ListEntry* ent = new ListEntry(obj);
if(head == NULL) {
head = ent;
tail = ent;
return;
}
if(head) {
ent -> setNext(head);
head = ent;
}
}
public:
ListEntry* get()
{
if(head) {
ListEntry* ent = head;
head = head -> getNext();
return ent;
}
else {
return NULL;
}
}
public:
ListEntry* peek()
{
if(head) {
ListEntry* ent = head;
// head = head -> GetNext();
return ent;
}
else {
return NULL;
}
}
public:
int getLength()
{
int n = 0;
if(head==NULL && tail== NULL) {
return n;
}
if(head) {
ListEntry* ent = head;
while(ent) {
ent = ent -> getNext();
n++;
}
}
return n;
}
};
}
|