Clearing the elements of the PriorityQueue using Javascript


We can clear the contents just by reassigning the container element to an empty array. For example, 

clear() {
   this.container = [];
}

Example

You can check if this function is working fine using − 

let q = new PriorityQueue(4);
q.enqueue("Hello", 3);
q.enqueue("World", 2);
q.enqueue("Foo", 8);
q.display();
q.clear();
q.display();

Output

This will give the output −

[ { data: 'World', priority: 2 },
  { data: 'Hello', priority: 3 },
  { data: 'Foo', priority: 8 } ]
[ ]

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 15-Jun-2020

61 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements