Grafalgo
Library of useful data structures and algorithms
|
This class implements a heap data structure. More...
#include <Dheap.h>
Public Member Functions | |
Dheap (int, int) | |
Constructor for Dheap class. | |
~Dheap () | |
Destructor for Dheap class. | |
void | clear () |
Remove all elements from heap. | |
void | resize (int) |
Resize a Dheap object. | |
void | expand (int) |
Expand the space available for this Dheap. | |
void | copyFrom (const Dheap &) |
Copy into Dheap from source. | |
index | findmin () const |
Find an item in the heap with the smallest key. | |
keytyp | key (index) const |
Get the key of item. | |
bool | member (index) const |
Determine if an item is in the heap. | |
bool | empty () const |
Determine if the heap is empty. | |
int | size () const |
Return size of heap. | |
void | insert (index, keytyp) |
Add item to the heap. | |
void | remove (index) |
Remove an item from the heap. | |
index | deletemin () |
Delete a minimum key item from the heap and return it. | |
void | changekey (index, keytyp) |
Change the key of an item in the heap. | |
string & | toString (string &) const |
Construct a string representation of this object. | |
Private Member Functions | |
index | minchild (index) |
void | siftup (index, int) |
Perform siftup operation to restore heap order. | |
void | siftdown (index, int) |
Perform siftdown operation to restore heap order. | |
void | makeSpace (int) |
Allocate and initialize space for Dheap. | |
void | freeSpace () |
Free dynamic storage used by Dheap. | |
Private Attributes | |
int | d |
base of heap | |
int | hn |
number of items in the heap | |
index * | h |
{h[1],...,h[hn]} is set of items | |
int * | pos |
pos[i] gives position of i in h | |
keytyp * | kee |
kee[i] is key of item i |
This class implements a heap data structure.
The heap elements are identified by integers in 1..n where n is specified when an object is constructed.
grafalgo::Dheap::Dheap | ( | int | size, |
int | dd | ||
) |
grafalgo::Dheap::~Dheap | ( | ) |
void grafalgo::Dheap::changekey | ( | index | i, |
keytyp | k | ||
) |
void grafalgo::Dheap::clear | ( | ) | [virtual] |
Remove all elements from heap.
Implements grafalgo::Adt.
Definition at line 85 of file Dheap.cpp.
void grafalgo::Dheap::copyFrom | ( | const Dheap & | source | ) |
int grafalgo::Dheap::deletemin | ( | ) | [inline] |
bool grafalgo::Dheap::empty | ( | ) | const [inline] |
void grafalgo::Dheap::expand | ( | int | size | ) | [virtual] |
Expand the space available for this Dheap.
Rebuilds old value in new space.
size | is the size of the resized object. |
Implements grafalgo::Adt.
Definition at line 78 of file Dheap.cpp.
int grafalgo::Dheap::findmin | ( | ) | const [inline] |
void grafalgo::Dheap::freeSpace | ( | ) | [private] |
void grafalgo::Dheap::insert | ( | index | i, |
keytyp | k | ||
) |
keytyp grafalgo::Dheap::key | ( | index | i | ) | const [inline] |
void grafalgo::Dheap::makeSpace | ( | int | size | ) | [private] |
bool grafalgo::Dheap::member | ( | index | i | ) | const [inline] |
void grafalgo::Dheap::remove | ( | index | i | ) |
void grafalgo::Dheap::resize | ( | int | size | ) | [virtual] |
Resize a Dheap object.
The old value is discarded.
size | is the size of the resize |
Implements grafalgo::Adt.
Definition at line 66 of file Dheap.cpp.
void grafalgo::Dheap::siftdown | ( | index | i, |
int | x | ||
) | [private] |
void grafalgo::Dheap::siftup | ( | index | i, |
int | x | ||
) | [private] |
string & grafalgo::Dheap::toString | ( | string & | s | ) | const [virtual] |
Construct a string representation of this object.
s | is a string in which the result is returned |
Implements grafalgo::Adt.