Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
30
Task/Priority-queue/Sidef/priority-queue.sidef
Normal file
30
Task/Priority-queue/Sidef/priority-queue.sidef
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
class PriorityQueue {
|
||||
has tasks = []
|
||||
|
||||
method insert (Number priority { _ >= 0 }, task) {
|
||||
for n in range(tasks.len, priority) {
|
||||
tasks[n] = []
|
||||
}
|
||||
tasks[priority].append(task)
|
||||
}
|
||||
|
||||
method get { tasks.first { !.is_empty } -> shift }
|
||||
method is_empty { tasks.all { .is_empty } }
|
||||
}
|
||||
|
||||
var pq = PriorityQueue()
|
||||
|
||||
[
|
||||
[3, 'Clear drains'],
|
||||
[4, 'Feed cat'],
|
||||
[5, 'Make tea'],
|
||||
[9, 'Sleep'],
|
||||
[3, 'Check email'],
|
||||
[1, 'Solve RC tasks'],
|
||||
[9, 'Exercise'],
|
||||
[2, 'Do taxes'],
|
||||
].each { |pair|
|
||||
pq.insert(pair...)
|
||||
}
|
||||
|
||||
say pq.get while !pq.is_empty
|
||||
Loading…
Add table
Add a link
Reference in a new issue