Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Rewrite this program in C while keeping its functionality equivalent to the Perl version.
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...
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);
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 a C# translation of this Perl snippet without changing its computational steps.
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);
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 Perl code snippet into C++ without altering its behavior.
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 <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 Perl snippet to C++ and keep its semantics consistent.
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 <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 functionally identical Java code for the snippet given in Perl.
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);
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 Perl to Java, ensuring the logic remains intact.
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);
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 this program in Python while keeping its functionality equivalent to the Perl version.
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);
>>> 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...
Maintain the same structure and functionality when rewriting this code in Python.
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);
>>> 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 an equivalent VB version of this Perl code.
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);
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 Perl version.
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);
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 Go while keeping its functionality equivalent to the Perl version.
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);
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 Perl snippet to Go and keep its semantics consistent.
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);
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 R to C with equivalent syntax and logic.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
#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 R version.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
#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 R to C#.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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 the following code from R to C#, ensuring the logic remains intact.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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 R code snippet into C++ without altering its behavior.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
#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"))...
Rewrite this program in C++ while keeping its functionality equivalent to the R version.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
#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 R code into Java without altering its purpose.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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 R implementation.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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) { ...
Translate the given R code snippet into Python without altering its behavior.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
>>> 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...
Can you help me rewrite this code in Python instead of R, keeping it the same logically?
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
>>> 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 the following code from R to VB, ensuring the logic remains intact.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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 R to VB, ensuring the logic remains intact.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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 the snippet below in Go so it works the same as the original R code.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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 R code into Go without altering its purpose.
PriorityQueue <- function() { keys <- values <- NULL insert <- function(key, value) { ord <- findInterval(key, keys) keys <<- append(keys, key, ord) values <<- append(values, value, ord) } pop <- function() { head <- list(key=keys[1],value=values[[1]]) values <<- values[-1] keys <<- keys...
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 Racket implementation into C, maintaining the same output and logic.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
#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 language-to-language conversion: from Racket to C, same semantics.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
#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 provided Racket code into C# while preserving the original functionality.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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...
Please provide an equivalent version of this Racket code in C#.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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...
Can you help me rewrite this code in C++ instead of Racket, keeping it the same logically?
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
#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++.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
#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 the same algorithm in Java as shown in this Racket implementation.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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 Racket implementation.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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 Racket snippet to Python and keep its semantics consistent.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
>>> 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 the following code from Racket to Python, ensuring the logic remains intact.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
>>> 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 Racket code into VB without altering its purpose.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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 Racket block to VB, preserving its control flow and logic.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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 Racket to Go, ensuring the logic remains intact.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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 Racket block to Go, preserving its control flow and logic.
#lang racket (require data/heap) (define pq (make-heap (λ(x y) (<= (second x) (second y))))) (define (insert! x pri) (heap-add! pq (list pri x))) (define (remove-min!) (begin0 (first (heap-min pq)) (heap-remove-min! pq))) (insert! 3 "Clear drains") (insert! 4 "Feed cat") (insert! 5 "Make tea") (insert...
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 provided REXX code into C while preserving the original functionality.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
#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...
Can you help me rewrite this code in C instead of REXX, keeping it the same logically?
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
#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 REXX code.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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 REXX to C# with equivalent syntax and logic.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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 REXX version.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
#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 REXX to C++, same semantics.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
#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 REXX to Java, same semantics.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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) { ...
Translate this program into Java but keep the logic exactly as in REXX.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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 REXX snippet to Python and keep its semantics consistent.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
>>> 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 REXX code into Python while preserving the original functionality.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
>>> 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 REXX function in VB with identical behavior.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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 provided REXX code into VB while preserving the original functionality.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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...
Please provide an equivalent version of this REXX code in Go.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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],...
Preserve the algorithm and functionality while converting the code from REXX to Go.
#=0; @.= say '══════ inserting tasks.'; call .ins 3 "Clear drains" call .ins 4 "Feed cat" call .ins 5 "Make tea" call .ins 1 "Solve RC tasks" ...
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 functionally identical C code for the snippet given in Ruby.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
#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 Ruby.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
#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...
Translate this program into C# but keep the logic exactly as in Ruby.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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 the following code from Ruby to C#, ensuring the logic remains intact.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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 Ruby to C++, same semantics.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
#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 this program into C++ but keep the logic exactly as in Ruby.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
#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 Ruby code snippet into Java without altering its behavior.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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) { ...
Keep all operations the same but rewrite the snippet in Java.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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 Python as shown below in Ruby.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
>>> 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 Ruby code into Python while preserving the original functionality.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
>>> 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 algorithm in VB as shown in this Ruby implementation.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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 Ruby to VB with equivalent syntax and logic.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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...
Write the same algorithm in Go as shown in this Ruby implementation.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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 functionally identical Go code for the snippet given in Ruby.
class PriorityQueueNaive def initialize(data=nil) @q = Hash.new {|h, k| h[k] = []} data.each {|priority, item| @q[priority] << item} if data @priorities = @q.keys.sort end def push(priority, item) @q[priority] << item @priorities = @q.keys.sort end def pop p = @priorities[0] ...
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 Scala snippet to C and keep its semantics consistent.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
#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 Scala code into C without altering its purpose.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
#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...
Can you help me rewrite this code in C# instead of Scala, keeping it the same logically?
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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...
Ensure the translated C# code behaves exactly like the original Scala snippet.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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...
Preserve the algorithm and functionality while converting the code from Scala to C++.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
#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"))...
Preserve the algorithm and functionality while converting the code from Scala to C++.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
#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 Scala implementation into Java, maintaining the same output and logic.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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) { ...
Keep all operations the same but rewrite the snippet in Java.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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 Scala block to Python, preserving its control flow and logic.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
>>> 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 Scala code.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
>>> 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...
Transform the following Scala implementation into VB, maintaining the same output and logic.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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 language-to-language conversion: from Scala to VB, same semantics.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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 Scala to Go.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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 the given Scala code snippet into Go without altering its behavior.
import java.util.PriorityQueue internal data class Task(val priority: Int, val name: String) : Comparable<Task> { override fun compareTo(other: Task) = when { priority < other.priority -> -1 priority > other.priority -> 1 else -> 0 } } private infix fun String.priority(priority: Int) =...
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 Swift to C without modifying what it does.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
#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 language-to-language conversion: from Swift to C, same semantics.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
#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...
Transform the following Swift implementation into C#, maintaining the same output and logic.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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...
Maintain the same structure and functionality when rewriting this code in C#.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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...
Preserve the algorithm and functionality while converting the code from Swift to C++.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
#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 Swift code in C++.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
#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 this program into Java but keep the logic exactly as in Swift.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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 Java so it works the same as the original Swift code.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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 Swift code into Python without altering its purpose.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
>>> 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 Swift block to Python, preserving its control flow and logic.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
>>> 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 algorithm in VB as shown in this Swift implementation.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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 Swift to VB with equivalent syntax and logic.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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 language-to-language conversion: from Swift to Go, same semantics.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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 an equivalent Go version of this Swift code.
class Task : Comparable, CustomStringConvertible { var priority : Int var name: String init(priority: Int, name: String) { self.priority = priority self.name = name } var description: String { return "\(priority), \(name)" } } func ==(t1: Task, t2: Task) -> Bool { return t1.priority == t2.prio...
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 algorithm in C as shown in this Tcl implementation.
package require struct::prioqueue set pq [struct::prioqueue] foreach {priority task} { 3 "Clear drains" 4 "Feed cat" 5 "Make tea" 1 "Solve RC tasks" 2 "Tax return" } { $pq put $task $priority } while {[$pq size]} { puts [$pq get] }
#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...
Translate the given Tcl code snippet into C without altering its behavior.
package require struct::prioqueue set pq [struct::prioqueue] foreach {priority task} { 3 "Clear drains" 4 "Feed cat" 5 "Make tea" 1 "Solve RC tasks" 2 "Tax return" } { $pq put $task $priority } while {[$pq size]} { puts [$pq get] }
#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 the snippet below in C# so it works the same as the original Tcl code.
package require struct::prioqueue set pq [struct::prioqueue] foreach {priority task} { 3 "Clear drains" 4 "Feed cat" 5 "Make tea" 1 "Solve RC tasks" 2 "Tax return" } { $pq put $task $priority } while {[$pq size]} { puts [$pq get] }
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...