DoublyLinkedQueue: Adjust whitespace.
No functional change.
This commit is contained in:
parent
5590a8194b
commit
65c74c6474
|
@ -26,148 +26,148 @@
|
||||||
template<typename Element,
|
template<typename Element,
|
||||||
typename GetLink = DoublyLinkedListStandardGetLink<Element> >
|
typename GetLink = DoublyLinkedListStandardGetLink<Element> >
|
||||||
class DoublyLinkedQueue {
|
class DoublyLinkedQueue {
|
||||||
private:
|
private:
|
||||||
typedef DoublyLinkedQueue<Element, GetLink> Queue;
|
typedef DoublyLinkedQueue<Element, GetLink> Queue;
|
||||||
typedef DoublyLinkedListLink<Element> Link;
|
typedef DoublyLinkedListLink<Element> Link;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class Iterator {
|
class Iterator {
|
||||||
public:
|
public:
|
||||||
Iterator(Queue *queue)
|
Iterator(Queue *queue)
|
||||||
:
|
:
|
||||||
fQueue(queue)
|
fQueue(queue)
|
||||||
{
|
{
|
||||||
Rewind();
|
Rewind();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator(const Iterator &other)
|
Iterator(const Iterator &other)
|
||||||
{
|
{
|
||||||
*this = other;
|
*this = other;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasNext() const
|
bool HasNext() const
|
||||||
{
|
{
|
||||||
return fNext;
|
return fNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
Element *Next()
|
Element *Next()
|
||||||
{
|
{
|
||||||
fCurrent = fNext;
|
fCurrent = fNext;
|
||||||
if (fNext)
|
if (fNext)
|
||||||
fNext = fQueue->GetNext(fNext);
|
fNext = fQueue->GetNext(fNext);
|
||||||
return fCurrent;
|
return fCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
Element *Remove()
|
Element *Remove()
|
||||||
{
|
{
|
||||||
Element *element = fCurrent;
|
Element *element = fCurrent;
|
||||||
if (fCurrent) {
|
if (fCurrent) {
|
||||||
fQueue->Remove(fCurrent);
|
fQueue->Remove(fCurrent);
|
||||||
fCurrent = NULL;
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator &operator=(const Iterator &other)
|
|
||||||
{
|
|
||||||
fQueue = other.fQueue;
|
|
||||||
fCurrent = other.fCurrent;
|
|
||||||
fNext = other.fNext;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rewind()
|
|
||||||
{
|
|
||||||
fCurrent = NULL;
|
fCurrent = NULL;
|
||||||
fNext = fQueue->First();
|
|
||||||
}
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
Iterator &operator=(const Iterator &other)
|
||||||
Queue *fQueue;
|
{
|
||||||
Element *fCurrent;
|
fQueue = other.fQueue;
|
||||||
Element *fNext;
|
fCurrent = other.fCurrent;
|
||||||
};
|
fNext = other.fNext;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
class ConstIterator {
|
void Rewind()
|
||||||
public:
|
{
|
||||||
ConstIterator(const Queue *queue)
|
fCurrent = NULL;
|
||||||
:
|
fNext = fQueue->First();
|
||||||
fQueue(queue)
|
}
|
||||||
{
|
|
||||||
Rewind();
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstIterator(const ConstIterator &other)
|
private:
|
||||||
{
|
Queue *fQueue;
|
||||||
*this = other;
|
Element *fCurrent;
|
||||||
}
|
Element *fNext;
|
||||||
|
};
|
||||||
|
|
||||||
bool HasNext() const
|
class ConstIterator {
|
||||||
{
|
public:
|
||||||
return fNext;
|
ConstIterator(const Queue *queue)
|
||||||
}
|
:
|
||||||
|
fQueue(queue)
|
||||||
|
{
|
||||||
|
Rewind();
|
||||||
|
}
|
||||||
|
|
||||||
Element *Next()
|
ConstIterator(const ConstIterator &other)
|
||||||
{
|
{
|
||||||
Element *element = fNext;
|
*this = other;
|
||||||
if (fNext)
|
}
|
||||||
fNext = fQueue->GetNext(fNext);
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstIterator &operator=(const ConstIterator &other)
|
bool HasNext() const
|
||||||
{
|
{
|
||||||
fQueue = other.fQueue;
|
return fNext;
|
||||||
fNext = other.fNext;
|
}
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rewind()
|
Element *Next()
|
||||||
{
|
{
|
||||||
fNext = fQueue->First();
|
Element *element = fNext;
|
||||||
}
|
if (fNext)
|
||||||
|
fNext = fQueue->GetNext(fNext);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
ConstIterator &operator=(const ConstIterator &other)
|
||||||
const Queue *fQueue;
|
{
|
||||||
Element *fNext;
|
fQueue = other.fQueue;
|
||||||
};
|
fNext = other.fNext;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
void Rewind()
|
||||||
DoublyLinkedQueue() : fFirst(NULL) {}
|
{
|
||||||
~DoublyLinkedQueue() {}
|
fNext = fQueue->First();
|
||||||
|
}
|
||||||
|
|
||||||
inline bool IsEmpty() const { return (fFirst == NULL); }
|
private:
|
||||||
|
const Queue *fQueue;
|
||||||
|
Element *fNext;
|
||||||
|
};
|
||||||
|
|
||||||
inline void Insert(Element *element);
|
public:
|
||||||
inline void Insert(Element *before, Element *element);
|
DoublyLinkedQueue() : fFirst(NULL) {}
|
||||||
inline void Add(Element *element);
|
~DoublyLinkedQueue() {}
|
||||||
inline void Remove(Element *element);
|
|
||||||
|
|
||||||
inline void Swap(Element *a, Element *b);
|
inline bool IsEmpty() const { return (fFirst == NULL); }
|
||||||
|
|
||||||
inline void MoveFrom(DOUBLY_LINKED_QUEUE_CLASS_NAME *fromList);
|
inline void Insert(Element *element);
|
||||||
|
inline void Insert(Element *before, Element *element);
|
||||||
|
inline void Add(Element *element);
|
||||||
|
inline void Remove(Element *element);
|
||||||
|
|
||||||
inline void RemoveAll();
|
inline void Swap(Element *a, Element *b);
|
||||||
inline void MakeEmpty() { RemoveAll(); }
|
|
||||||
|
|
||||||
inline Element *First() const { return fFirst; }
|
inline void MoveFrom(DOUBLY_LINKED_QUEUE_CLASS_NAME *fromList);
|
||||||
inline Element *Head() const { return fFirst; }
|
|
||||||
|
|
||||||
inline Element *RemoveHead();
|
inline void RemoveAll();
|
||||||
|
inline void MakeEmpty() { RemoveAll(); }
|
||||||
|
|
||||||
inline Element *GetPrevious(Element *element) const;
|
inline Element *First() const { return fFirst; }
|
||||||
inline Element *GetNext(Element *element) const;
|
inline Element *Head() const { return fFirst; }
|
||||||
|
|
||||||
inline int32 Size() const;
|
inline Element *RemoveHead();
|
||||||
// O(n)!
|
|
||||||
|
|
||||||
inline Iterator GetIterator() { return Iterator(this); }
|
inline Element *GetPrevious(Element *element) const;
|
||||||
inline ConstIterator GetIterator() const { return ConstIterator(this); }
|
inline Element *GetNext(Element *element) const;
|
||||||
|
|
||||||
private:
|
inline int32 Size() const;
|
||||||
Element *fFirst;
|
// O(n)!
|
||||||
|
|
||||||
static GetLink sGetLink;
|
inline Iterator GetIterator() { return Iterator(this); }
|
||||||
|
inline ConstIterator GetIterator() const { return ConstIterator(this); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Element *fFirst;
|
||||||
|
|
||||||
|
static GetLink sGetLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue