Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Produce a functionally identical Go code for the snippet given in Julia. | abstract type AbstractNode{T} end
struct EmptyNode{T} <: AbstractNode{T} end
mutable struct Node{T} <: AbstractNode{T}
value::T
pred::AbstractNode{T}
succ::AbstractNode{T}
end
| type dlNode struct {
string
next, prev *dlNode
}
|
Port the following code from Lua to C with equivalent syntax and logic. | local node = { data=data, prev=nil, next=nil }
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Translate this program into C# but keep the logic exactly as in Lua. | local node = { data=data, prev=nil, next=nil }
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Ensure the translated C++ code behaves exactly like the original Lua snippet. | local node = { data=data, prev=nil, next=nil }
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Transform the following Lua implementation into Java, maintaining the same output and logic. | local node = { data=data, prev=nil, next=nil }
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Convert the following code from Lua to Python, ensuring the logic remains intact. | local node = { data=data, prev=nil, next=nil }
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Convert this Lua snippet to VB and keep its semantics consistent. | local node = { data=data, prev=nil, next=nil }
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Translate this program into C but keep the logic exactly as in Mathematica. | CreateDataStructure["DoublyLinkedList"]
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Convert this Mathematica snippet to C# and keep its semantics consistent. | CreateDataStructure["DoublyLinkedList"]
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Please provide an equivalent version of this Mathematica code in C++. | CreateDataStructure["DoublyLinkedList"]
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Generate an equivalent Java version of this Mathematica code. | CreateDataStructure["DoublyLinkedList"]
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Write the same code in Python as shown below in Mathematica. | CreateDataStructure["DoublyLinkedList"]
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Produce a functionally identical VB code for the snippet given in Mathematica. | CreateDataStructure["DoublyLinkedList"]
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Transform the following Nim implementation into C, maintaining the same output and logic. | type
Node[T] = ref TNode[T]
TNode[T] = object
next, prev: Node[T]
data: T
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Change the programming language of this snippet from Nim to C# without modifying what it does. | type
Node[T] = ref TNode[T]
TNode[T] = object
next, prev: Node[T]
data: T
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Translate the given Nim code snippet into C++ without altering its behavior. | type
Node[T] = ref TNode[T]
TNode[T] = object
next, prev: Node[T]
data: T
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Write a version of this Nim function in Java with identical behavior. | type
Node[T] = ref TNode[T]
TNode[T] = object
next, prev: Node[T]
data: T
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Write the same algorithm in Python as shown in this Nim implementation. | type
Node[T] = ref TNode[T]
TNode[T] = object
next, prev: Node[T]
data: T
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Port the following code from Nim to VB with equivalent syntax and logic. | type
Node[T] = ref TNode[T]
TNode[T] = object
next, prev: Node[T]
data: T
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Please provide an equivalent version of this Nim code in Go. | type
Node[T] = ref TNode[T]
TNode[T] = object
next, prev: Node[T]
data: T
| type dlNode struct {
string
next, prev *dlNode
}
|
Translate the given OCaml code snippet into C without altering its behavior. | type 'a dlink = {
mutable data: 'a;
mutable next: 'a dlink option;
mutable prev: 'a dlink option;
}
let dlink_of_list li =
let f prev_dlink x =
let dlink = {
data = x;
prev = None;
next = prev_dlink }
in
begin match prev_dlink with
| None -> ()
| Some prev_dlink ->
prev_dlink.prev <- Some dlink
end;
Some dlink
in
List.fold_left f None (List.rev li)
;;
let list_of_dlink =
let rec aux acc = function
| None -> List.rev acc
| Some{ data = d;
prev = _;
next = next } -> aux (d::acc) next
in
aux []
;;
let iter_forward_dlink f =
let rec aux = function
| None -> ()
| Some{ data = d;
prev = _;
next = next } -> f d; aux next
in
aux
;;
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Port the provided OCaml code into C# while preserving the original functionality. | type 'a dlink = {
mutable data: 'a;
mutable next: 'a dlink option;
mutable prev: 'a dlink option;
}
let dlink_of_list li =
let f prev_dlink x =
let dlink = {
data = x;
prev = None;
next = prev_dlink }
in
begin match prev_dlink with
| None -> ()
| Some prev_dlink ->
prev_dlink.prev <- Some dlink
end;
Some dlink
in
List.fold_left f None (List.rev li)
;;
let list_of_dlink =
let rec aux acc = function
| None -> List.rev acc
| Some{ data = d;
prev = _;
next = next } -> aux (d::acc) next
in
aux []
;;
let iter_forward_dlink f =
let rec aux = function
| None -> ()
| Some{ data = d;
prev = _;
next = next } -> f d; aux next
in
aux
;;
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Translate this program into Java but keep the logic exactly as in OCaml. | type 'a dlink = {
mutable data: 'a;
mutable next: 'a dlink option;
mutable prev: 'a dlink option;
}
let dlink_of_list li =
let f prev_dlink x =
let dlink = {
data = x;
prev = None;
next = prev_dlink }
in
begin match prev_dlink with
| None -> ()
| Some prev_dlink ->
prev_dlink.prev <- Some dlink
end;
Some dlink
in
List.fold_left f None (List.rev li)
;;
let list_of_dlink =
let rec aux acc = function
| None -> List.rev acc
| Some{ data = d;
prev = _;
next = next } -> aux (d::acc) next
in
aux []
;;
let iter_forward_dlink f =
let rec aux = function
| None -> ()
| Some{ data = d;
prev = _;
next = next } -> f d; aux next
in
aux
;;
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Rewrite the snippet below in Python so it works the same as the original OCaml code. | type 'a dlink = {
mutable data: 'a;
mutable next: 'a dlink option;
mutable prev: 'a dlink option;
}
let dlink_of_list li =
let f prev_dlink x =
let dlink = {
data = x;
prev = None;
next = prev_dlink }
in
begin match prev_dlink with
| None -> ()
| Some prev_dlink ->
prev_dlink.prev <- Some dlink
end;
Some dlink
in
List.fold_left f None (List.rev li)
;;
let list_of_dlink =
let rec aux acc = function
| None -> List.rev acc
| Some{ data = d;
prev = _;
next = next } -> aux (d::acc) next
in
aux []
;;
let iter_forward_dlink f =
let rec aux = function
| None -> ()
| Some{ data = d;
prev = _;
next = next } -> f d; aux next
in
aux
;;
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Port the following code from OCaml to VB with equivalent syntax and logic. | type 'a dlink = {
mutable data: 'a;
mutable next: 'a dlink option;
mutable prev: 'a dlink option;
}
let dlink_of_list li =
let f prev_dlink x =
let dlink = {
data = x;
prev = None;
next = prev_dlink }
in
begin match prev_dlink with
| None -> ()
| Some prev_dlink ->
prev_dlink.prev <- Some dlink
end;
Some dlink
in
List.fold_left f None (List.rev li)
;;
let list_of_dlink =
let rec aux acc = function
| None -> List.rev acc
| Some{ data = d;
prev = _;
next = next } -> aux (d::acc) next
in
aux []
;;
let iter_forward_dlink f =
let rec aux = function
| None -> ()
| Some{ data = d;
prev = _;
next = next } -> f d; aux next
in
aux
;;
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Can you help me rewrite this code in Go instead of OCaml, keeping it the same logically? | type 'a dlink = {
mutable data: 'a;
mutable next: 'a dlink option;
mutable prev: 'a dlink option;
}
let dlink_of_list li =
let f prev_dlink x =
let dlink = {
data = x;
prev = None;
next = prev_dlink }
in
begin match prev_dlink with
| None -> ()
| Some prev_dlink ->
prev_dlink.prev <- Some dlink
end;
Some dlink
in
List.fold_left f None (List.rev li)
;;
let list_of_dlink =
let rec aux acc = function
| None -> List.rev acc
| Some{ data = d;
prev = _;
next = next } -> aux (d::acc) next
in
aux []
;;
let iter_forward_dlink f =
let rec aux = function
| None -> ()
| Some{ data = d;
prev = _;
next = next } -> f d; aux next
in
aux
;;
| type dlNode struct {
string
next, prev *dlNode
}
|
Write the same algorithm in C as shown in this Pascal implementation. | type link_ptr = ^link;
data_ptr = ^data;
link = record
prev: link_ptr;
next: link_ptr;
data: data_ptr;
end;
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Write a version of this Pascal function in C# with identical behavior. | type link_ptr = ^link;
data_ptr = ^data;
link = record
prev: link_ptr;
next: link_ptr;
data: data_ptr;
end;
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Translate the given Pascal code snippet into C++ without altering its behavior. | type link_ptr = ^link;
data_ptr = ^data;
link = record
prev: link_ptr;
next: link_ptr;
data: data_ptr;
end;
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Preserve the algorithm and functionality while converting the code from Pascal to Java. | type link_ptr = ^link;
data_ptr = ^data;
link = record
prev: link_ptr;
next: link_ptr;
data: data_ptr;
end;
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Produce a functionally identical Python code for the snippet given in Pascal. | type link_ptr = ^link;
data_ptr = ^data;
link = record
prev: link_ptr;
next: link_ptr;
data: data_ptr;
end;
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Rewrite the snippet below in VB so it works the same as the original Pascal code. | type link_ptr = ^link;
data_ptr = ^data;
link = record
prev: link_ptr;
next: link_ptr;
data: data_ptr;
end;
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Rewrite this program in Go while keeping its functionality equivalent to the Pascal version. | type link_ptr = ^link;
data_ptr = ^data;
link = record
prev: link_ptr;
next: link_ptr;
data: data_ptr;
end;
| type dlNode struct {
string
next, prev *dlNode
}
|
Port the provided Perl code into C while preserving the original functionality. | my %node = (
data => 'say what',
next => \%foo_node,
prev => \%bar_node,
);
$node{next} = \%quux_node;
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Ensure the translated C# code behaves exactly like the original Perl snippet. | my %node = (
data => 'say what',
next => \%foo_node,
prev => \%bar_node,
);
$node{next} = \%quux_node;
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Translate the given Perl code snippet into C++ without altering its behavior. | my %node = (
data => 'say what',
next => \%foo_node,
prev => \%bar_node,
);
$node{next} = \%quux_node;
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Write a version of this Perl function in Java with identical behavior. | my %node = (
data => 'say what',
next => \%foo_node,
prev => \%bar_node,
);
$node{next} = \%quux_node;
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Convert the following code from Perl to Python, ensuring the logic remains intact. | my %node = (
data => 'say what',
next => \%foo_node,
prev => \%bar_node,
);
$node{next} = \%quux_node;
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Maintain the same structure and functionality when rewriting this code in VB. | my %node = (
data => 'say what',
next => \%foo_node,
prev => \%bar_node,
);
$node{next} = \%quux_node;
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Translate this program into Go but keep the logic exactly as in Perl. | my %node = (
data => 'say what',
next => \%foo_node,
prev => \%bar_node,
);
$node{next} = \%quux_node;
| type dlNode struct {
string
next, prev *dlNode
}
|
Change the programming language of this snippet from Racket to C without modifying what it does. | (define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Generate an equivalent C# version of this Racket code. | (define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Produce a language-to-language conversion: from Racket to C++, same semantics. | (define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Can you help me rewrite this code in Java instead of Racket, keeping it the same logically? | (define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Ensure the translated Python code behaves exactly like the original Racket snippet. | (define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Can you help me rewrite this code in VB instead of Racket, keeping it the same logically? | (define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Generate an equivalent Go version of this Racket code. | (define-struct dlist (head tail) #:mutable)
(define-struct dlink (content prev next) #:mutable)
| type dlNode struct {
string
next, prev *dlNode
}
|
Ensure the translated C code behaves exactly like the original REXX snippet. |
call sy 'initializing the list.' ; call @init
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)."
call sy 'showing list' ; call @show
call sy 'adding to head: Oy!' ; call @put "Oy!",0
call sy 'showing list' ; call @show
exit
p: return word(arg(1), 1)
sy: say; say left('', 30) "βββ" arg(1) 'βββ'; return
@init: $.@=; @adjust: $.@=space($.@); $.#=words($.@); return
@hasopt: arg o; return pos(o, opt)\==0
@size: return $.#
@del: procedure expose $.; arg k,m; call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_; call @adjust; return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end
return strip(_)
@parms: arg opt
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1); return
@put: procedure expose $.; parse arg x,k; k=p(k $.#+1); call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k); call @adjust
return
@show: procedure expose $.; parse arg k,m,dir; if dir==-1 & k=='' then k=$.#
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Write the same algorithm in C# as shown in this REXX implementation. |
call sy 'initializing the list.' ; call @init
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)."
call sy 'showing list' ; call @show
call sy 'adding to head: Oy!' ; call @put "Oy!",0
call sy 'showing list' ; call @show
exit
p: return word(arg(1), 1)
sy: say; say left('', 30) "βββ" arg(1) 'βββ'; return
@init: $.@=; @adjust: $.@=space($.@); $.#=words($.@); return
@hasopt: arg o; return pos(o, opt)\==0
@size: return $.#
@del: procedure expose $.; arg k,m; call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_; call @adjust; return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end
return strip(_)
@parms: arg opt
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1); return
@put: procedure expose $.; parse arg x,k; k=p(k $.#+1); call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k); call @adjust
return
@show: procedure expose $.; parse arg k,m,dir; if dir==-1 & k=='' then k=$.#
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Convert this REXX snippet to C++ and keep its semantics consistent. |
call sy 'initializing the list.' ; call @init
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)."
call sy 'showing list' ; call @show
call sy 'adding to head: Oy!' ; call @put "Oy!",0
call sy 'showing list' ; call @show
exit
p: return word(arg(1), 1)
sy: say; say left('', 30) "βββ" arg(1) 'βββ'; return
@init: $.@=; @adjust: $.@=space($.@); $.#=words($.@); return
@hasopt: arg o; return pos(o, opt)\==0
@size: return $.#
@del: procedure expose $.; arg k,m; call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_; call @adjust; return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end
return strip(_)
@parms: arg opt
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1); return
@put: procedure expose $.; parse arg x,k; k=p(k $.#+1); call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k); call @adjust
return
@show: procedure expose $.; parse arg k,m,dir; if dir==-1 & k=='' then k=$.#
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Port the provided REXX code into Java while preserving the original functionality. |
call sy 'initializing the list.' ; call @init
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)."
call sy 'showing list' ; call @show
call sy 'adding to head: Oy!' ; call @put "Oy!",0
call sy 'showing list' ; call @show
exit
p: return word(arg(1), 1)
sy: say; say left('', 30) "βββ" arg(1) 'βββ'; return
@init: $.@=; @adjust: $.@=space($.@); $.#=words($.@); return
@hasopt: arg o; return pos(o, opt)\==0
@size: return $.#
@del: procedure expose $.; arg k,m; call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_; call @adjust; return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end
return strip(_)
@parms: arg opt
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1); return
@put: procedure expose $.; parse arg x,k; k=p(k $.#+1); call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k); call @adjust
return
@show: procedure expose $.; parse arg k,m,dir; if dir==-1 & k=='' then k=$.#
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Please provide an equivalent version of this REXX code in Python. |
call sy 'initializing the list.' ; call @init
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)."
call sy 'showing list' ; call @show
call sy 'adding to head: Oy!' ; call @put "Oy!",0
call sy 'showing list' ; call @show
exit
p: return word(arg(1), 1)
sy: say; say left('', 30) "βββ" arg(1) 'βββ'; return
@init: $.@=; @adjust: $.@=space($.@); $.#=words($.@); return
@hasopt: arg o; return pos(o, opt)\==0
@size: return $.#
@del: procedure expose $.; arg k,m; call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_; call @adjust; return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end
return strip(_)
@parms: arg opt
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1); return
@put: procedure expose $.; parse arg x,k; k=p(k $.#+1); call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k); call @adjust
return
@show: procedure expose $.; parse arg k,m,dir; if dir==-1 & k=='' then k=$.#
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Generate an equivalent VB version of this REXX code. |
call sy 'initializing the list.' ; call @init
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)."
call sy 'showing list' ; call @show
call sy 'adding to head: Oy!' ; call @put "Oy!",0
call sy 'showing list' ; call @show
exit
p: return word(arg(1), 1)
sy: say; say left('', 30) "βββ" arg(1) 'βββ'; return
@init: $.@=; @adjust: $.@=space($.@); $.#=words($.@); return
@hasopt: arg o; return pos(o, opt)\==0
@size: return $.#
@del: procedure expose $.; arg k,m; call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_; call @adjust; return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end
return strip(_)
@parms: arg opt
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1); return
@put: procedure expose $.; parse arg x,k; k=p(k $.#+1); call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k); call @adjust
return
@show: procedure expose $.; parse arg k,m,dir; if dir==-1 & k=='' then k=$.#
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Change the following REXX code into Go without altering its purpose. |
call sy 'initializing the list.' ; call @init
call sy 'building list: Was it a cat I saw' ; call @put "Was it a cat I saw"
call sy 'displaying list size.' ; say "list size="@size()
call sy 'forward list' ; call @show
call sy 'backward list' ; call @show ,,-1
call sy 'showing 4th item' ; call @show 4,1
call sy 'showing 5th & 6th items' ; call @show 5,2
call sy 'adding item before item 4: black' ; call @put "black",4
call sy 'showing list' ; call @show
call sy 'adding to tail: there, in the ...' ; call @put "there, in the shadows, stalking its prey (and next meal)."
call sy 'showing list' ; call @show
call sy 'adding to head: Oy!' ; call @put "Oy!",0
call sy 'showing list' ; call @show
exit
p: return word(arg(1), 1)
sy: say; say left('', 30) "βββ" arg(1) 'βββ'; return
@init: $.@=; @adjust: $.@=space($.@); $.#=words($.@); return
@hasopt: arg o; return pos(o, opt)\==0
@size: return $.#
@del: procedure expose $.; arg k,m; call @parms 'km'
_=subword($.@, k, k-1) subword($.@, k+m)
$.@=_; call @adjust; return
@get: procedure expose $.; arg k,m,dir,_
call @parms 'kmd'
do j=k for m by dir while j>0 & j<=$.#
_=_ subword($.@, j, 1)
end
return strip(_)
@parms: arg opt
if @hasopt('k') then k=min($.#+1, max(1, p(k 1)))
if @hasopt('m') then m=p(m 1)
if @hasopt('d') then dir=p(dir 1); return
@put: procedure expose $.; parse arg x,k; k=p(k $.#+1); call @parms 'k'
$.@=subword($.@, 1, max(0, k-1)) x subword($.@, k); call @adjust
return
@show: procedure expose $.; parse arg k,m,dir; if dir==-1 & k=='' then k=$.#
m=p(m $.#); call @parms 'kmd'; say @get(k,m, dir); return
| type dlNode struct {
string
next, prev *dlNode
}
|
Port the following code from Ruby to C with equivalent syntax and logic. | class DListNode < ListNode
attr_accessor :prev
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
ary.map! {|i| new i }
ary.inject(f) {|p, c| p.succ = c; c.prev = p; c }
end
end
list = DListNode.from_values 1,2,3,4
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Change the programming language of this snippet from Ruby to C# without modifying what it does. | class DListNode < ListNode
attr_accessor :prev
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
ary.map! {|i| new i }
ary.inject(f) {|p, c| p.succ = c; c.prev = p; c }
end
end
list = DListNode.from_values 1,2,3,4
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Produce a functionally identical C++ code for the snippet given in Ruby. | class DListNode < ListNode
attr_accessor :prev
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
ary.map! {|i| new i }
ary.inject(f) {|p, c| p.succ = c; c.prev = p; c }
end
end
list = DListNode.from_values 1,2,3,4
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Change the programming language of this snippet from Ruby to Java without modifying what it does. | class DListNode < ListNode
attr_accessor :prev
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
ary.map! {|i| new i }
ary.inject(f) {|p, c| p.succ = c; c.prev = p; c }
end
end
list = DListNode.from_values 1,2,3,4
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Produce a language-to-language conversion: from Ruby to Python, same semantics. | class DListNode < ListNode
attr_accessor :prev
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
ary.map! {|i| new i }
ary.inject(f) {|p, c| p.succ = c; c.prev = p; c }
end
end
list = DListNode.from_values 1,2,3,4
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Write the same code in VB as shown below in Ruby. | class DListNode < ListNode
attr_accessor :prev
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
ary.map! {|i| new i }
ary.inject(f) {|p, c| p.succ = c; c.prev = p; c }
end
end
list = DListNode.from_values 1,2,3,4
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Write the same algorithm in Go as shown in this Ruby implementation. | class DListNode < ListNode
attr_accessor :prev
def initialize(value, prev=nil, succ=nil)
@value = value
@prev = prev
@prev.succ = self if prev
@succ = succ
@succ.prev = self if succ
end
def self.from_values(*ary)
ary << (f = ary.pop)
ary.map! {|i| new i }
ary.inject(f) {|p, c| p.succ = c; c.prev = p; c }
end
end
list = DListNode.from_values 1,2,3,4
| type dlNode struct {
string
next, prev *dlNode
}
|
Convert this Scala snippet to C and keep its semantics consistent. |
class Node<T: Number>(var data: T, var prev: Node<T>? = null, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
}
return sb.toString()
}
}
fun main(args: Array<String>) {
val n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Translate the given Scala code snippet into C# without altering its behavior. |
class Node<T: Number>(var data: T, var prev: Node<T>? = null, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
}
return sb.toString()
}
}
fun main(args: Array<String>) {
val n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Convert this Scala snippet to C++ and keep its semantics consistent. |
class Node<T: Number>(var data: T, var prev: Node<T>? = null, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
}
return sb.toString()
}
}
fun main(args: Array<String>) {
val n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Convert this Scala snippet to Java and keep its semantics consistent. |
class Node<T: Number>(var data: T, var prev: Node<T>? = null, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
}
return sb.toString()
}
}
fun main(args: Array<String>) {
val n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Translate the given Scala code snippet into Python without altering its behavior. |
class Node<T: Number>(var data: T, var prev: Node<T>? = null, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
}
return sb.toString()
}
}
fun main(args: Array<String>) {
val n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Write a version of this Scala function in VB with identical behavior. |
class Node<T: Number>(var data: T, var prev: Node<T>? = null, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
}
return sb.toString()
}
}
fun main(args: Array<String>) {
val n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Write a version of this Scala function in Go with identical behavior. |
class Node<T: Number>(var data: T, var prev: Node<T>? = null, var next: Node<T>? = null) {
override fun toString(): String {
val sb = StringBuilder(this.data.toString())
var node = this.next
while (node != null) {
sb.append(" -> ", node.data.toString())
node = node.next
}
return sb.toString()
}
}
fun main(args: Array<String>) {
val n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}
| type dlNode struct {
string
next, prev *dlNode
}
|
Produce a language-to-language conversion: from Swift to C, same semantics. | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Convert the following code from Swift to C#, ensuring the logic remains intact. | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Produce a language-to-language conversion: from Swift to C++, same semantics. | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Port the provided Swift code into Java while preserving the original functionality. | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Rewrite this program in Python while keeping its functionality equivalent to the Swift version. | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Please provide an equivalent version of this Swift code in VB. | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Keep all operations the same but rewrite the snippet in Go. | typealias NodePtr<T> = UnsafeMutablePointer<Node<T>>
class Node<T> {
var value: T
fileprivate var prev: NodePtr<T>?
fileprivate var next: NodePtr<T>?
init(value: T, prev: NodePtr<T>? = nil, next: NodePtr<T>? = nil) {
self.value = value
self.prev = prev
self.next = next
}
}
| type dlNode struct {
string
next, prev *dlNode
}
|
Please provide an equivalent version of this Tcl code in C. | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
set next {*}$args
}
method previous args {
set prev {*}$args
}
}
| struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
|
Produce a language-to-language conversion: from Tcl to C#, same semantics. | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
set next {*}$args
}
method previous args {
set prev {*}$args
}
}
| class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
|
Ensure the translated C++ code behaves exactly like the original Tcl snippet. | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
set next {*}$args
}
method previous args {
set prev {*}$args
}
}
| template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
|
Convert this Tcl snippet to Java and keep its semantics consistent. | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
set next {*}$args
}
method previous args {
set prev {*}$args
}
}
| public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
|
Convert this Tcl snippet to Python and keep its semantics consistent. | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
set next {*}$args
}
method previous args {
set prev {*}$args
}
}
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Write the same algorithm in VB as shown in this Tcl implementation. | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
set next {*}$args
}
method previous args {
set prev {*}$args
}
}
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Convert the following code from Tcl to Go, ensuring the logic remains intact. | oo::class create List {
variable content next prev
constructor {value {list ""}} {
set content $value
set next $list
set prev ""
if {$next ne ""} {
$next previous [self]
}
}
method value args {
set content {*}$args
}
method next args {
set next {*}$args
}
method previous args {
set prev {*}$args
}
}
| type dlNode struct {
string
next, prev *dlNode
}
|
Change the following C code into Rust without altering its purpose. | struct Node
{
struct Node *next;
struct Node *prev;
void *data;
};
| use std::collections::LinkedList;
fn main() {
let list = LinkedList::<i32>::new();
}
|
Produce a functionally identical Rust code for the snippet given in Java. | public class Node<T> {
private T element;
private Node<T> next, prev;
public Node<T>(){
next = prev = element = null;
}
public Node<T>(Node<T> n, Node<T> p, T elem){
next = n;
prev = p;
element = elem;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> getNext(){
return next;
}
public void setElem(T elem){
element = elem;
}
public T getElem(){
return element;
}
public void setNext(Node<T> n){
next = n;
}
public Node<T> setPrev(Node<T> p){
prev = p;
}
public getPrev(){
return prev;
}
}
| use std::collections::LinkedList;
fn main() {
let list = LinkedList::<i32>::new();
}
|
Transform the following Go implementation into Rust, maintaining the same output and logic. | type dlNode struct {
string
next, prev *dlNode
}
| use std::collections::LinkedList;
fn main() {
let list = LinkedList::<i32>::new();
}
|
Rewrite this program in Python while keeping its functionality equivalent to the Rust version. | use std::collections::LinkedList;
fn main() {
let list = LinkedList::<i32>::new();
}
| class Node(object):
def __init__(self, data = None, prev = None, next = None):
self.prev = prev
self.next = next
self.data = data
def __str__(self):
return str(self.data)
def __repr__(self):
return repr(self.data)
def iter_forward(self):
c = self
while c != None:
yield c
c = c.next
def iter_backward(self):
c = self
while c != None:
yield c
c = c.prev
|
Port the provided Rust code into VB while preserving the original functionality. | use std::collections::LinkedList;
fn main() {
let list = LinkedList::<i32>::new();
}
| Public Class Node(Of T)
Public Value As T
Public [Next] As Node(Of T)
Public Previous As Node(Of T)
End Class
|
Change the following C# code into Rust without altering its purpose. | class Link
{
public int Item { get; set; }
public Link Prev { get; set; }
public Link Next { get; set; }
public Link(int item, Link prev = null, Link next = null) {
Item = item;
Prev = prev;
Next = next;
}
}
| use std::collections::LinkedList;
fn main() {
let list = LinkedList::<i32>::new();
}
|
Generate an equivalent Rust version of this C++ code. | template <typename T>
struct Node
{
Node* next;
Node* prev;
T data;
};
| use std::collections::LinkedList;
fn main() {
let list = LinkedList::<i32>::new();
}
|
Transform the following Ada implementation into C#, maintaining the same output and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| static void Main(string[] args)
{
Console.WriteLine(DotProduct(new decimal[] { 1, 3, -5 }, new decimal[] { 4, -2, -1 }));
Console.Read();
}
private static decimal DotProduct(decimal[] vec1, decimal[] vec2)
{
if (vec1 == null)
return 0;
if (vec2 == null)
return 0;
if (vec1.Length != vec2.Length)
return 0;
decimal tVal = 0;
for (int x = 0; x < vec1.Length; x++)
{
tVal += vec1[x] * vec2[x];
}
return tVal;
}
|
Convert this Ada block to C#, preserving its control flow and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| static void Main(string[] args)
{
Console.WriteLine(DotProduct(new decimal[] { 1, 3, -5 }, new decimal[] { 4, -2, -1 }));
Console.Read();
}
private static decimal DotProduct(decimal[] vec1, decimal[] vec2)
{
if (vec1 == null)
return 0;
if (vec2 == null)
return 0;
if (vec1.Length != vec2.Length)
return 0;
decimal tVal = 0;
for (int x = 0; x < vec1.Length; x++)
{
tVal += vec1[x] * vec2[x];
}
return tVal;
}
|
Generate a C translation of this Ada snippet without changing its computational steps. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| #include <stdio.h>
#include <stdlib.h>
int dot_product(int *, int *, size_t);
int
main(void)
{
int a[3] = {1, 3, -5};
int b[3] = {4, -2, -1};
printf("%d\n", dot_product(a, b, sizeof(a) / sizeof(a[0])));
return EXIT_SUCCESS;
}
int
dot_product(int *a, int *b, size_t n)
{
int sum = 0;
size_t i;
for (i = 0; i < n; i++) {
sum += a[i] * b[i];
}
return sum;
}
|
Write the same code in C as shown below in Ada. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| #include <stdio.h>
#include <stdlib.h>
int dot_product(int *, int *, size_t);
int
main(void)
{
int a[3] = {1, 3, -5};
int b[3] = {4, -2, -1};
printf("%d\n", dot_product(a, b, sizeof(a) / sizeof(a[0])));
return EXIT_SUCCESS;
}
int
dot_product(int *a, int *b, size_t n)
{
int sum = 0;
size_t i;
for (i = 0; i < n; i++) {
sum += a[i] * b[i];
}
return sum;
}
|
Generate a C++ translation of this Ada snippet without changing its computational steps. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| #include <iostream>
#include <numeric>
int main()
{
int a[] = { 1, 3, -5 };
int b[] = { 4, -2, -1 };
std::cout << std::inner_product(a, a + sizeof(a) / sizeof(a[0]), b, 0) << std::endl;
return 0;
}
|
Convert this Ada block to C++, preserving its control flow and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| #include <iostream>
#include <numeric>
int main()
{
int a[] = { 1, 3, -5 };
int b[] = { 4, -2, -1 };
std::cout << std::inner_product(a, a + sizeof(a) / sizeof(a[0]), b, 0) << std::endl;
return 0;
}
|
Produce a language-to-language conversion: from Ada to Go, same semantics. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| package main
import (
"errors"
"fmt"
"log"
)
var (
v1 = []int{1, 3, -5}
v2 = []int{4, -2, -1}
)
func dot(x, y []int) (r int, err error) {
if len(x) != len(y) {
return 0, errors.New("incompatible lengths")
}
for i, xi := range x {
r += xi * y[i]
}
return
}
func main() {
d, err := dot([]int{1, 3, -5}, []int{4, -2, -1})
if err != nil {
log.Fatal(err)
}
fmt.Println(d)
}
|
Produce a language-to-language conversion: from Ada to Go, same semantics. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| package main
import (
"errors"
"fmt"
"log"
)
var (
v1 = []int{1, 3, -5}
v2 = []int{4, -2, -1}
)
func dot(x, y []int) (r int, err error) {
if len(x) != len(y) {
return 0, errors.New("incompatible lengths")
}
for i, xi := range x {
r += xi * y[i]
}
return
}
func main() {
d, err := dot([]int{1, 3, -5}, []int{4, -2, -1})
if err != nil {
log.Fatal(err)
}
fmt.Println(d)
}
|
Preserve the algorithm and functionality while converting the code from Ada to Java. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| public class DotProduct {
public static void main(String[] args) {
double[] a = {1, 3, -5};
double[] b = {4, -2, -1};
System.out.println(dotProd(a,b));
}
public static double dotProd(double[] a, double[] b){
if(a.length != b.length){
throw new IllegalArgumentException("The dimensions have to be equal!");
}
double sum = 0;
for(int i = 0; i < a.length; i++){
sum += a[i] * b[i];
}
return sum;
}
}
|
Rewrite this program in Java while keeping its functionality equivalent to the Ada version. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| public class DotProduct {
public static void main(String[] args) {
double[] a = {1, 3, -5};
double[] b = {4, -2, -1};
System.out.println(dotProd(a,b));
}
public static double dotProd(double[] a, double[] b){
if(a.length != b.length){
throw new IllegalArgumentException("The dimensions have to be equal!");
}
double sum = 0;
for(int i = 0; i < a.length; i++){
sum += a[i] * b[i];
}
return sum;
}
}
|
Maintain the same structure and functionality when rewriting this code in Python. | with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
type vect is array(Positive range <>) of Integer;
v1 : vect := (1,3,-5);
v2 : vect := (4,-2,-1);
function dotprod(a: vect; b: vect) return Integer is
sum : Integer := 0;
begin
if not (a'Length=b'Length) then raise Constraint_Error; end if;
for p in a'Range loop
sum := sum + a(p)*b(p);
end loop;
return sum;
end dotprod;
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
| def dotp(a,b):
assert len(a) == len(b), 'Vector sizes must match'
return sum(aterm * bterm for aterm,bterm in zip(a, b))
if __name__ == '__main__':
a, b = [1, 3, -5], [4, -2, -1]
assert dotp(a,b) == 3
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.