Skip to content

Commit

Permalink
getHeap added to PQ
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh07bharvada committed Dec 15, 2020
1 parent 1757ae3 commit 578edef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Structures-Wiz is a JavaScript based npm package for using awesome data structur
- [enqueue](#pq-enqueue)
- [dequeue](#pq-dequeue)
- [peek](#pq-peek)
- [getHeap](#pq-getHeap)
- [getSortedHeap](#pq-getSortedHeap)
- [getKth](#pq-getKth)
- [getHeight](#pq-getHeight)
Expand Down Expand Up @@ -239,6 +240,35 @@ console.log("Peak Value is :",peekValue); //[ 70 , 200 ]

```

#### getHeap() <a name="pq-getHeap"></a>

Returns the current heap
```javascript

import { PriorityQueue } from 'structures-wiz';

const priorityQ = new PriorityQueue();

priorityQ.enqueue(10, 100);
priorityQ.enqueue(20, 80);
priorityQ.enqueue(60, 90);
priorityQ.enqueue(40, 20);
priorityQ.enqueue(70, 200);
priorityQ.enqueue(50, 40);

const Heap = priorityQ.getHeap();
console.log("Heap is :",Heap);
/*[
[ 70, 200 ],
[ 10, 100 ],
[ 60, 90 ],
[ 40, 20 ],
[ 20, 80 ],
[ 50, 40 ]
]*/

```

#### getSortedHeap() <a name="pq-getSortedHeap"></a>

Returns the current heap in the sorted order ( Descending if config is set as Max-Heap else Ascending in case of Min-Heap)
Expand Down
7 changes: 7 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ class PriorityQueue {
this.heap = [];
this.height = -1;
}

/**
* @What - Returns heap
*/
getHeap(){
return this.heap;
}
}

class Stack {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "structures-wiz",
"version": "1.0.12",
"version": "1.0.13",
"description": "Structures-Wiz is a JavaScript based npm package for using awesome data structures like Stacks, Queue, LinkedList, PriorityQueues.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 578edef

Please sign in to comment.