adding lab
This commit is contained in:
68
labs/priority_queues/priority_queue.h
Normal file
68
labs/priority_queues/priority_queue.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef priority_queue_h_
|
||||
#define priority_queue_h_
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
template <class T>
|
||||
class priority_queue {
|
||||
private:
|
||||
std::vector<T> m_heap;
|
||||
|
||||
public:
|
||||
priority_queue() {}
|
||||
|
||||
priority_queue( std::vector<T> const& values )
|
||||
{
|
||||
}
|
||||
|
||||
const T& top() const
|
||||
{
|
||||
assert( !m_heap.empty() );
|
||||
return m_heap[0];
|
||||
}
|
||||
|
||||
void push( const T& entry )
|
||||
{
|
||||
}
|
||||
|
||||
void pop()
|
||||
{
|
||||
assert( !m_heap.empty() );
|
||||
}
|
||||
|
||||
int size() { return m_heap.size(); }
|
||||
bool empty() { return m_heap.empty(); }
|
||||
|
||||
|
||||
// The following three functions are used for debugging.
|
||||
|
||||
// Check to see that internally the heap property is realized.
|
||||
bool check_heap( )
|
||||
{
|
||||
return this->check_heap( this->m_heap );
|
||||
}
|
||||
|
||||
// Check an external vector to see that the heap property is realized.
|
||||
bool check_heap( const std::vector<T>& heap )
|
||||
{
|
||||
}
|
||||
|
||||
// A utility to print the contents of the heap. Use it for debugging.
|
||||
void print_heap( std::ostream & ostr )
|
||||
{
|
||||
for ( unsigned int i=0; i<m_heap.size(); ++i )
|
||||
ostr << i << ": " << m_heap[i] << std::endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
void heap_sort( std::vector<T> & v )
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user