Skip to content

In place heap (priority queue) for embedded systems such as arduino, stm32,etc. O(logN) complexity

Notifications You must be signed in to change notification settings

maksimpiriyev/in_place_heap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

in_place_heap

In place heap (priority queue) for embedded systems such as arduino, stm32,etc. O(logN) complexity, always returns the min element. Easy to use code samples below

int size = 1024;
heap<int,size> heap_with_size;
heap<int> h;

for(int i=10;i>=0;i--){
   h.push(i);
}
    
while(h.size()){
   int t = h.top();
   h.pop();
   printf("%d, ",t);
}

prints out as

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,

also the below code with custom class or struct:

class test{
public:
    int d = 0;
    test(){}
    test(int d):d(d){}
    bool operator < (const test& t){ return d < t.d;}
};

heap<test> h2;
for(int i=10;i>=0;i--){
   h2.push(test(i));
}

while(h2.size()){
   auto t = h2.top();
   h2.pop();
   printf("%d, ",t.d);
}

About

In place heap (priority queue) for embedded systems such as arduino, stm32,etc. O(logN) complexity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages