1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2019-2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#pragma once
#include "LinkedList.h"
namespace iSTD
{
/*****************************************************************************\
Template Parameters
\*****************************************************************************/
#define QueueTemplateList class Type, class CAllocatorType
#define CQueueType CQueue<Type,CAllocatorType>
/*****************************************************************************\
Class:
CQueue
Description:
Implements an linked-list-based queue
\*****************************************************************************/
template<QueueTemplateList>
class CQueue : public CLinkedListType
{
public:
bool Push( const Type element );
Type Pop( void );
Type Top( void ) const;
};
/*****************************************************************************\
Function:
CQueue::Push
Description:
Pushes an element on the queue
Input:
const Type element
Output:
bool - success or fail
\*****************************************************************************/
template<QueueTemplateList>
bool CQueueType::Push( const Type element )
{
// Add element to the top of list
return this->Add( element );
}
/*****************************************************************************\
Function:
CQueue::Pop
Description:
Pops an element off the queue
Input:
none
Output:
Type - element
\*****************************************************************************/
template<QueueTemplateList>
Type CQueueType::Pop( void )
{
Type element = {0};
if( this->IsEmpty() )
{
ASSERT(0);
}
else
{
// Get the last element on the list
typename CQueue::CIterator end = this->End();
--end;
element = *end;
// Remove the last element
this->Remove( end );
}
return element;
}
/*****************************************************************************\
Function:
CQueue::Top
Description:
Returns the top element of the queue
Input:
none
Output:
Type - element
\*****************************************************************************/
template<QueueTemplateList>
Type CQueueType::Top( void ) const
{
Type element = {0};
if( this->IsEmpty() )
{
ASSERT(0);
}
else
{
// Get the last element on the list
typename CQueueType::CConstIterator end = this->End();
--end;
element = *end;
}
return element;
}
} // iSTD
|