Visualisierung2
myMaxheap.h
Go to the documentation of this file.
1 #pragma once
2 #if !defined(TUP_INCLUDED)
3 #define TUP_INCLUDED
4 struct mytuple {
5  double m; // stored value
6  int i; // row index
7  int j; // column index
8  int k; // heap index
9 };
10 #endif
11 
12 #if !defined(MAXHEAP_INCLUDED)
13 #define MAXHEAP_INCLUDED
14 
15 #include <iostream>
16 
17 /* Because using this heap requires us to be able to modify an arbitrary element's
18  data in constant O(1) time, I use to tricky tactic of having elements in an array-
19  based heap only contain addresses to the data, rather than the data itself. In this
20  manner, an external program may freely modify an element of the heap, given that it
21  possesses a pointer to said element (in an array-based heap, the addresses and the
22  value in that address are not bound and thus may change during the heapify() operation).
23 */
26 struct hnode
27 {
29 };
30 const int heapmin = 3;
31 //const double tiny = -4294967296.0;
32 
33 
38 class myMaxheap
39 {
40 private:
41  hnode *A;
42  int heaplimit;
43  int arraysize;
44  bool isempty;
45 
46  int downsift(int i);
47  int upsift (int i);
48  int left (int i);
49  int right (int i);
50  int parent (int i);
51  void grow();
52  void shrink();
53 
54 public:
55  myMaxheap(void); // default constructor
56  myMaxheap(int size);
57  ~myMaxheap(void); // default destructor
58 
59  int heapSize();
60  bool heapIsEmpty();
61  mytuple *insertItem(const mytuple newData);
64  void printHeap();
65  void printHeapTop10();
66  void updateItem(mytuple *address, mytuple newData);
67  void updateItem(mytuple *address, double newStored);
68  void deleteItem(mytuple *address);
69  int returnArraysize();
70  int returnHeaplimit();
71 
72 };
73 
74 #endif
int upsift(int i)
Funktion um das Element von A[i] richtig in den Heap zu ordnen.
Definition: myMaxheap.cpp:109
int downsift(int i)
Funktion um das Element von A[i] richtig in den Heap zu ordnen.
Definition: myMaxheap.cpp:78
void updateItem(mytuple *address, mytuple newData)
Updated das Element an der angegeben Adresse mit dem uebergeben Wert.
Definition: myMaxheap.cpp:214
void printHeap()
Gibt die Elemente im Heap aus.
Definition: myMaxheap.cpp:275
mytuple returnMaximum()
Gibt das maximale Element im Heap zurueck. Keine Aenderungen im Heap.
Definition: myMaxheap.cpp:56
int returnArraysize()
Gibt die Groesse des Wertearrays zurueck.
Definition: myMaxheap.cpp:67
int parent(int i)
Gibt den Index des Elternknotens zurueck.
Definition: myMaxheap.cpp:140
~myMaxheap(void)
Definition: myMaxheap.cpp:36
int k
Index des Elements im Heap.
Definition: myElement.h:11
int left(int i)
Gibt den Index des Linken Kindex zurueck.
Definition: myMaxheap.cpp:132
int heapSize()
gibt die Groesse des heaps zurueck (maxheap-1).
Definition: myMaxheap.cpp:269
hnode * A
Arrayspeicher des Maxheaps.
Definition: myMaxheap.h:41
const int heapmin
Definition: myMaxheap.h:30
int returnHeaplimit()
Gibt den Index vom ersten ungenutzen Element zurueck.
Definition: myMaxheap.cpp:71
mytuple * insertItem(const mytuple newData)
Fuegt newData in den Heap ein und gibt die Adresse davon zurueck.
Definition: myMaxheap.cpp:193
bool heapIsEmpty()
True wenn der Heap leer ist, andersfalls false.
Definition: myMaxheap.cpp:265
mytuple popMaximum()
Gibt das maximale Element im Heap zurueck und entfernt es aus dem Heap. Ordnet dannach den Heap neu...
Definition: myMaxheap.cpp:46
void grow()
Erhoeht die Groesse des A Arrays.
Definition: myMaxheap.cpp:145
bool isempty
Gibt an ob der Heap leer ist. True..ist leer, False..nicht leer.
Definition: myMaxheap.h:44
int right(int i)
Gibt den Index des rechten Kindes zurueck.
Definition: myMaxheap.cpp:136
void deleteItem(mytuple *address)
Entfernt das Element an der angegeben Adresse.
Definition: myMaxheap.cpp:235
myMaxheap(void)
Definition: myMaxheap.cpp:4
void shrink()
Verringert die Groesse des A Arrays.
Definition: myMaxheap.cpp:168
int i
Zeilenindex des Elements.
Definition: myElement.h:9
double m
Abgelegter Wert/Parameter.
Definition: myElement.h:8
int arraysize
Groesse des Arrays.
Definition: myMaxheap.h:43
void printHeapTop10()
Gibt die groessten 10 Elemente im Heap aus.
Definition: myMaxheap.cpp:283
int j
Spaltenindex des Elements.
Definition: myElement.h:10
int heaplimit
Erstes unbenutzes Element im Heap.
Definition: myMaxheap.h:42
mytuple * d
Definition: myMaxheap.h:28