Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Rewrite this program in Go while keeping its functionality equivalent to the Haskell version.
import Data.PQueue.Prio.Min main = print (toList (fromList [(3, "Clear drains"),(4, "Feed cat"),(5, "Make tea"),(1, "Solve RC tasks"), (2, "Tax return")]))
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Convert this J block to C, preserving its control flow and logic.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Produce a functionally identical C code for the snippet given in J.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Ensure the translated C# code behaves exactly like the original J snippet.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Rewrite the snippet below in C# so it works the same as the original J code.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Generate an equivalent C++ version of this J code.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Convert this J snippet to C++ and keep its semantics consistent.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Please provide an equivalent version of this J code in Java.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Convert this J snippet to Java and keep its semantics consistent.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Change the following J code into Python without altering its purpose.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Generate a Python translation of this J snippet without changing its computational steps.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Change the programming language of this snippet from J to VB without modifying what it does.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Port the following code from J to VB with equivalent syntax and logic.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Convert this J block to Go, preserving its control flow and logic.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Transform the following J implementation into Go, maintaining the same output and logic.
coclass 'priorityQueue' PRI=: '' QUE=: '' insert=:4 :0 p=. PRI,x q=. QUE,y assert. p -:&$ q assert. 1 = #$q ord=: \: p QUE=: ord { q PRI=: ord { p i.0 0 ) topN=:3 :0 assert y<:#PRI r=. y{.QUE PRI=: y}.PRI QUE=: y}.QUE r )
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Transform the following Julia implementation into C, maintaining the same output and logic.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Change the following Julia code into C without altering its purpose.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Preserve the algorithm and functionality while converting the code from Julia to C#.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Write a version of this Julia function in C# with identical behavior.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Convert this Julia block to C++, preserving its control flow and logic.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Maintain the same structure and functionality when rewriting this code in C++.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Maintain the same structure and functionality when rewriting this code in Java.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Write the same code in Java as shown below in Julia.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Generate an equivalent Python version of this Julia code.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Write the same code in Python as shown below in Julia.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Rewrite this program in VB while keeping its functionality equivalent to the Julia version.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Convert this Julia block to VB, preserving its control flow and logic.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Maintain the same structure and functionality when rewriting this code in Go.
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Can you help me rewrite this code in Go instead of Julia, keeping it the same logically?
using Base.Collections test = ["Clear drains" 3; "Feed cat" 4; "Make tea" 5; "Solve RC tasks" 1; "Tax return" 2] task = PriorityQueue(Base.Order.Reverse) for i in 1:size(test)[1] enqueue!(task, test[i,1], test[i,2]) end println("Tasks, completed according to priority:") while !ise...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Ensure the translated C code behaves exactly like the original Lua snippet.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Preserve the algorithm and functionality while converting the code from Lua to C.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Write the same code in C# as shown below in Lua.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Write a version of this Lua function in C# with identical behavior.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Change the programming language of this snippet from Lua to C++ without modifying what it does.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Convert this Lua snippet to C++ and keep its semantics consistent.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Produce a language-to-language conversion: from Lua to Java, same semantics.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Please provide an equivalent version of this Lua code in Java.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Convert this Lua block to Python, preserving its control flow and logic.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Ensure the translated Python code behaves exactly like the original Lua snippet.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Rewrite the snippet below in VB so it works the same as the original Lua code.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Ensure the translated VB code behaves exactly like the original Lua snippet.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Change the programming language of this snippet from Lua to Go without modifying what it does.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Produce a language-to-language conversion: from Lua to Go, same semantics.
PriorityQueue = { __index = { put = function(self, p, v) local q = self[p] if not q then q = {first = 1, last = 0} self[p] = q end q.last = q.last + 1 q[q.last] = v end, pop = function(self) ...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Write the same code in C as shown below in Mathematica.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Port the following code from Mathematica to C with equivalent syntax and logic.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Generate an equivalent C# version of this Mathematica code.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Port the following code from Mathematica to C# with equivalent syntax and logic.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Rewrite this program in C++ while keeping its functionality equivalent to the Mathematica version.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Change the following Mathematica code into C++ without altering its purpose.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Write a version of this Mathematica function in Java with identical behavior.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Write the same algorithm in Java as shown in this Mathematica implementation.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Produce a functionally identical Python code for the snippet given in Mathematica.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Write a version of this Mathematica function in Python with identical behavior.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Produce a functionally identical VB code for the snippet given in Mathematica.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Produce a functionally identical VB code for the snippet given in Mathematica.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Maintain the same structure and functionality when rewriting this code in Go.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Translate this program into Go but keep the logic exactly as in Mathematica.
push = Function[{queue, priority, item}, queue = SortBy[Append[queue, {priority, item}], First], HoldFirst]; pop = Function[queue, If[Length@queue == 0, Null, With[{item = queue[[-1, 2]]}, queue = Most@queue; item]], HoldFirst]; peek = Function[queue, If[Length@queue == 0, Null, Max[queue[[All, 1]]...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Generate a C translation of this Nim snippet without changing its computational steps.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Rewrite this program in C while keeping its functionality equivalent to the Nim version.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Write the same algorithm in C# as shown in this Nim implementation.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Produce a language-to-language conversion: from Nim to C#, same semantics.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Translate the given Nim code snippet into C++ without altering its behavior.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Convert the following code from Nim to C++, ensuring the logic remains intact.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Can you help me rewrite this code in Java instead of Nim, keeping it the same logically?
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Preserve the algorithm and functionality while converting the code from Nim to Java.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Produce a functionally identical Python code for the snippet given in Nim.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Rewrite the snippet below in Python so it works the same as the original Nim code.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Port the provided Nim code into VB while preserving the original functionality.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Maintain the same structure and functionality when rewriting this code in VB.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Preserve the algorithm and functionality while converting the code from Nim to Go.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Rewrite this program in Go while keeping its functionality equivalent to the Nim version.
type PriElem[T] = tuple data: T pri: int PriQueue[T] = object buf: seq[PriElem[T]] count: int proc initPriQueue[T](initialSize = 4): PriQueue[T] = result.buf.newSeq(initialSize) result.buf.setLen(1) result.count = 0 proc add[T](q: var PriQueue[T], data: T, pri: int) = var n = q.buf.len ...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Change the following OCaml code into C without altering its purpose.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Change the following OCaml code into C without altering its purpose.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Rewrite this program in C# while keeping its functionality equivalent to the OCaml version.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Write a version of this OCaml function in C# with identical behavior.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Produce a functionally identical C++ code for the snippet given in OCaml.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Generate a C++ translation of this OCaml snippet without changing its computational steps.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Translate the given OCaml code snippet into Java without altering its behavior.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Write the same algorithm in Java as shown in this OCaml implementation.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Rewrite the snippet below in Python so it works the same as the original OCaml code.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Change the following OCaml code into Python without altering its purpose.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Change the programming language of this snippet from OCaml to VB without modifying what it does.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Generate a VB translation of this OCaml snippet without changing its computational steps.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Change the programming language of this snippet from OCaml to Go without modifying what it does.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Port the following code from OCaml to Go with equivalent syntax and logic.
module PQ = Base.PriorityQueue let () = let tasks = [ 3, "Clear drains"; 4, "Feed cat"; 5, "Make tea"; 1, "Solve RC tasks"; 2, "Tax return"; ] in let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in List.iter (PQ.add pq) tasks; while not (PQ.is_empty pq) do let _, task = P...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Change the following Pascal code into C without altering its purpose.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Produce a functionally identical C code for the snippet given in Pascal.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...
Write a version of this Pascal function in C# with identical behavior.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Port the following code from Pascal to C# with equivalent syntax and logic.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
using System; using System.Collections.Generic; namespace PriorityQueueExample { class Program { static void Main(string[] args) { var p = new PriorityQueue<string, int>(); p.Enqueue("Clear drains", 3); p.Enqueue("Feed cat", 4); p.Enqueue("Make tea", 5); p.Enqueue("Solve RC tasks", 1); p.En...
Generate an equivalent C++ version of this Pascal code.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Maintain the same structure and functionality when rewriting this code in C++.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
#include <iostream> #include <string> #include <queue> #include <utility> int main() { std::priority_queue<std::pair<int, std::string> > pq; pq.push(std::make_pair(3, "Clear drains")); pq.push(std::make_pair(4, "Feed cat")); pq.push(std::make_pair(5, "Make tea")); pq.push(std::make_pair(1, "Solve RC tasks"))...
Transform the following Pascal implementation into Java, maintaining the same output and logic.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Convert the following code from Pascal to Java, ensuring the logic remains intact.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
import java.util.PriorityQueue; class Task implements Comparable<Task> { final int priority; final String name; public Task(int p, String n) { priority = p; name = n; } public String toString() { return priority + ", " + name; } public int compareTo(Task other) { ...
Change the following Pascal code into Python without altering its purpose.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Convert this Pascal block to Python, preserving its control flow and logic.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
>>> import queue >>> pq = queue.PriorityQueue() >>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")): pq.put(item) >>> while not pq.empty(): print(pq.get_nowait()) (1, 'Solve RC tasks') (2, 'Tax return') (3, 'Clear drains') (4, 'Feed cat') (5, 'Ma...
Preserve the algorithm and functionality while converting the code from Pascal to VB.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Rewrite this program in VB while keeping its functionality equivalent to the Pascal version.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
Type Tuple Priority As Integer Data As String End Type Dim a() As Tuple Dim n As Integer Private Function Left(i As Integer) As Integer Left = 2 * i + 1 End Function Private Function Right(i As Integer) As Integer Right = 2 * i + 2 End Function Private Function Parent(i As Integer) As Integer Paren...
Convert the following code from Pascal to Go, ensuring the logic remains intact.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Port the following code from Pascal to Go with equivalent syntax and logic.
program PriorityQueueTest; uses Classes; Type TItem = record Priority:Integer; Value:string; end; PItem = ^TItem; TPriorityQueue = class(Tlist) procedure Push(Priority:Integer;Value:string); procedure SortPriority(); function Pop():String; function Empty:Boolean; end; procedure TPriorityQueue.Pu...
package main import ( "fmt" "container/heap" ) type Task struct { priority int name string } type TaskPQ []Task func (self TaskPQ) Len() int { return len(self) } func (self TaskPQ) Less(i, j int) bool { return self[i].priority < self[j].priority } func (self TaskPQ) Swap(i, j int) { self[i],...
Change the programming language of this snippet from Perl to C without modifying what it does.
use strict; use warnings; use feature 'say'; use Heap::Priority; my $h = Heap::Priority->new; $h->highest_first(); $h->add(@$_) for ["Clear drains", 3], ["Feed cat", 4], ["Make tea", 5], ["Solve RC tasks", 1], ["Tax return", 2]; say while ($_ = $h->pop);
#include <stdio.h> #include <stdlib.h> typedef struct { int priority; char *data; } node_t; typedef struct { node_t *nodes; int len; int size; } heap_t; void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes...