Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Generate an equivalent Java version of this Swift code.
func multiFactorial(_ n: Int, k: Int) -> Int { return stride(from: n, to: 0, by: -k).reduce(1, *) } let multis = (1...5).map({degree in (1...10).map({member in multiFactorial(member, k: degree) }) }) for (i, degree) in multis.enumerated() { print("Degree \(i + 1): \(degree)") }
public class MultiFact { private static long multiFact(long n, int deg){ long ans = 1; for(long i = n; i > 0; i -= deg){ ans *= i; } return ans; } public static void main(String[] args){ for(int deg = 1; deg <= 5; deg++){ System.out.print("degree " + deg + ":"); for(long n = 1; n <= 10; n++){ ...
Maintain the same structure and functionality when rewriting this code in Python.
func multiFactorial(_ n: Int, k: Int) -> Int { return stride(from: n, to: 0, by: -k).reduce(1, *) } let multis = (1...5).map({degree in (1...10).map({member in multiFactorial(member, k: degree) }) }) for (i, degree) in multis.enumerated() { print("Degree \(i + 1): \(degree)") }
>>> from functools import reduce >>> from operator import mul >>> def mfac(n, m): return reduce(mul, range(n, 0, -m)) >>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)])) 1: [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800] 2: [1, 2, 3, 8, 15, 48, 105, 384, 945, 3840] 3: [1, 2,...
Transform the following Swift implementation into Python, maintaining the same output and logic.
func multiFactorial(_ n: Int, k: Int) -> Int { return stride(from: n, to: 0, by: -k).reduce(1, *) } let multis = (1...5).map({degree in (1...10).map({member in multiFactorial(member, k: degree) }) }) for (i, degree) in multis.enumerated() { print("Degree \(i + 1): \(degree)") }
>>> from functools import reduce >>> from operator import mul >>> def mfac(n, m): return reduce(mul, range(n, 0, -m)) >>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)])) 1: [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800] 2: [1, 2, 3, 8, 15, 48, 105, 384, 945, 3840] 3: [1, 2,...
Change the programming language of this snippet from Swift to VB without modifying what it does.
func multiFactorial(_ n: Int, k: Int) -> Int { return stride(from: n, to: 0, by: -k).reduce(1, *) } let multis = (1...5).map({degree in (1...10).map({member in multiFactorial(member, k: degree) }) }) for (i, degree) in multis.enumerated() { print("Degree \(i + 1): \(degree)") }
Function multifactorial(n,d) If n = 0 Then multifactorial = 1 Else For i = n To 1 Step -d If i = n Then multifactorial = n Else multifactorial = multifactorial * i End If Next End If End Function For j = 1 To 5 WScript.StdOut.Write "Degree " & j & ": " For k = 1 To 10 If k = 10 Then WS...
Convert the following code from Swift to VB, ensuring the logic remains intact.
func multiFactorial(_ n: Int, k: Int) -> Int { return stride(from: n, to: 0, by: -k).reduce(1, *) } let multis = (1...5).map({degree in (1...10).map({member in multiFactorial(member, k: degree) }) }) for (i, degree) in multis.enumerated() { print("Degree \(i + 1): \(degree)") }
Function multifactorial(n,d) If n = 0 Then multifactorial = 1 Else For i = n To 1 Step -d If i = n Then multifactorial = n Else multifactorial = multifactorial * i End If Next End If End Function For j = 1 To 5 WScript.StdOut.Write "Degree " & j & ": " For k = 1 To 10 If k = 10 Then WS...
Convert the following code from Swift to Go, ensuring the logic remains intact.
func multiFactorial(_ n: Int, k: Int) -> Int { return stride(from: n, to: 0, by: -k).reduce(1, *) } let multis = (1...5).map({degree in (1...10).map({member in multiFactorial(member, k: degree) }) }) for (i, degree) in multis.enumerated() { print("Degree \(i + 1): \(degree)") }
package main import "fmt" func multiFactorial(n, k int) int { r := 1 for ; n > 1; n -= k { r *= n } return r } func main() { for k := 1; k <= 5; k++ { fmt.Print("degree ", k, ":") for n := 1; n <= 10; n++ { fmt.Print(" ", multiFactorial(n, k)) } ...
Convert this Swift snippet to Go and keep its semantics consistent.
func multiFactorial(_ n: Int, k: Int) -> Int { return stride(from: n, to: 0, by: -k).reduce(1, *) } let multis = (1...5).map({degree in (1...10).map({member in multiFactorial(member, k: degree) }) }) for (i, degree) in multis.enumerated() { print("Degree \(i + 1): \(degree)") }
package main import "fmt" func multiFactorial(n, k int) int { r := 1 for ; n > 1; n -= k { r *= n } return r } func main() { for k := 1; k <= 5; k++ { fmt.Print("degree ", k, ":") for n := 1; n <= 10; n++ { fmt.Print(" ", multiFactorial(n, k)) } ...
Please provide an equivalent version of this Tcl code in C.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
#include <stdio.h> #define HIGHEST_DEGREE 5 #define LARGEST_NUMBER 10 int multifact(int n, int deg){ return n <= deg ? n : n * multifact(n - deg, deg); } int multifact_i(int n, int deg){ int result = n; while (n >= deg + 1){ result *= (n - deg); n -= deg; } return result; } int main(vo...
Produce a language-to-language conversion: from Tcl to C, same semantics.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
#include <stdio.h> #define HIGHEST_DEGREE 5 #define LARGEST_NUMBER 10 int multifact(int n, int deg){ return n <= deg ? n : n * multifact(n - deg, deg); } int multifact_i(int n, int deg){ int result = n; while (n >= deg + 1){ result *= (n - deg); n -= deg; } return result; } int main(vo...
Rewrite the snippet below in C# so it works the same as the original Tcl code.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
namespace RosettaCode.Multifactorial { using System; using System.Linq; internal static class Program { private static void Main() { Console.WriteLine(string.Join(Environment.NewLine, Enumerable.Range(1, 5) ...
Change the programming language of this snippet from Tcl to C# without modifying what it does.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
namespace RosettaCode.Multifactorial { using System; using System.Linq; internal static class Program { private static void Main() { Console.WriteLine(string.Join(Environment.NewLine, Enumerable.Range(1, 5) ...
Transform the following Tcl implementation into C++, maintaining the same output and logic.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
#include <algorithm> #include <iostream> #include <iterator> int main(void) { for (int g = 1; g < 10; g++) { int v[11], n=0; generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;}); std::cout << std::endl; } return 0; }
Translate this program into C++ but keep the logic exactly as in Tcl.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
#include <algorithm> #include <iostream> #include <iterator> int main(void) { for (int g = 1; g < 10; g++) { int v[11], n=0; generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;}); std::cout << std::endl; } return 0; }
Rewrite this program in Java while keeping its functionality equivalent to the Tcl version.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
public class MultiFact { private static long multiFact(long n, int deg){ long ans = 1; for(long i = n; i > 0; i -= deg){ ans *= i; } return ans; } public static void main(String[] args){ for(int deg = 1; deg <= 5; deg++){ System.out.print("degree " + deg + ":"); for(long n = 1; n <= 10; n++){ ...
Produce a functionally identical Java code for the snippet given in Tcl.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
public class MultiFact { private static long multiFact(long n, int deg){ long ans = 1; for(long i = n; i > 0; i -= deg){ ans *= i; } return ans; } public static void main(String[] args){ for(int deg = 1; deg <= 5; deg++){ System.out.print("degree " + deg + ":"); for(long n = 1; n <= 10; n++){ ...
Change the programming language of this snippet from Tcl to Python without modifying what it does.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
>>> from functools import reduce >>> from operator import mul >>> def mfac(n, m): return reduce(mul, range(n, 0, -m)) >>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)])) 1: [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800] 2: [1, 2, 3, 8, 15, 48, 105, 384, 945, 3840] 3: [1, 2,...
Generate an equivalent Python version of this Tcl code.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
>>> from functools import reduce >>> from operator import mul >>> def mfac(n, m): return reduce(mul, range(n, 0, -m)) >>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)])) 1: [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800] 2: [1, 2, 3, 8, 15, 48, 105, 384, 945, 3840] 3: [1, 2,...
Preserve the algorithm and functionality while converting the code from Tcl to VB.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
Function multifactorial(n,d) If n = 0 Then multifactorial = 1 Else For i = n To 1 Step -d If i = n Then multifactorial = n Else multifactorial = multifactorial * i End If Next End If End Function For j = 1 To 5 WScript.StdOut.Write "Degree " & j & ": " For k = 1 To 10 If k = 10 Then WS...
Write the same code in VB as shown below in Tcl.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
Function multifactorial(n,d) If n = 0 Then multifactorial = 1 Else For i = n To 1 Step -d If i = n Then multifactorial = n Else multifactorial = multifactorial * i End If Next End If End Function For j = 1 To 5 WScript.StdOut.Write "Degree " & j & ": " For k = 1 To 10 If k = 10 Then WS...
Produce a language-to-language conversion: from Tcl to Go, same semantics.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
package main import "fmt" func multiFactorial(n, k int) int { r := 1 for ; n > 1; n -= k { r *= n } return r } func main() { for k := 1; k <= 5; k++ { fmt.Print("degree ", k, ":") for n := 1; n <= 10; n++ { fmt.Print(" ", multiFactorial(n, k)) } ...
Ensure the translated Go code behaves exactly like the original Tcl snippet.
package require Tcl 8.6 proc mfact {n m} { set mm [expr {-$m}] for {set r $n} {[incr n $mm] > 1} {set r [expr {$r * $n}]} {} return $r } foreach n {1 2 3 4 5 6 7 8 9 10} { puts $n:[join [lmap m {1 2 3 4 5 6 7 8 9 10} {mfact $m $n}] ,] }
package main import "fmt" func multiFactorial(n, k int) int { r := 1 for ; n > 1; n -= k { r *= n } return r } func main() { for k := 1; k <= 5; k++ { fmt.Print("degree ", k, ":") for n := 1; n <= 10; n++ { fmt.Print(" ", multiFactorial(n, k)) } ...
Can you help me rewrite this code in Rust instead of C, keeping it the same logically?
#include <stdio.h> #define HIGHEST_DEGREE 5 #define LARGEST_NUMBER 10 int multifact(int n, int deg){ return n <= deg ? n : n * multifact(n - deg, deg); } int multifact_i(int n, int deg){ int result = n; while (n >= deg + 1){ result *= (n - deg); n -= deg; } return result; } int main(vo...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Can you help me rewrite this code in Rust instead of C, keeping it the same logically?
#include <stdio.h> #define HIGHEST_DEGREE 5 #define LARGEST_NUMBER 10 int multifact(int n, int deg){ return n <= deg ? n : n * multifact(n - deg, deg); } int multifact_i(int n, int deg){ int result = n; while (n >= deg + 1){ result *= (n - deg); n -= deg; } return result; } int main(vo...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Rewrite the snippet below in Rust so it works the same as the original C# code.
namespace RosettaCode.Multifactorial { using System; using System.Linq; internal static class Program { private static void Main() { Console.WriteLine(string.Join(Environment.NewLine, Enumerable.Range(1, 5) ...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Can you help me rewrite this code in Rust instead of C#, keeping it the same logically?
namespace RosettaCode.Multifactorial { using System; using System.Linq; internal static class Program { private static void Main() { Console.WriteLine(string.Join(Environment.NewLine, Enumerable.Range(1, 5) ...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Translate this program into Rust but keep the logic exactly as in Go.
package main import "fmt" func multiFactorial(n, k int) int { r := 1 for ; n > 1; n -= k { r *= n } return r } func main() { for k := 1; k <= 5; k++ { fmt.Print("degree ", k, ":") for n := 1; n <= 10; n++ { fmt.Print(" ", multiFactorial(n, k)) } ...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Write the same algorithm in Python as shown in this Rust implementation.
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
>>> from functools import reduce >>> from operator import mul >>> def mfac(n, m): return reduce(mul, range(n, 0, -m)) >>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)])) 1: [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800] 2: [1, 2, 3, 8, 15, 48, 105, 384, 945, 3840] 3: [1, 2,...
Generate a VB translation of this Rust snippet without changing its computational steps.
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Function multifactorial(n,d) If n = 0 Then multifactorial = 1 Else For i = n To 1 Step -d If i = n Then multifactorial = n Else multifactorial = multifactorial * i End If Next End If End Function For j = 1 To 5 WScript.StdOut.Write "Degree " & j & ": " For k = 1 To 10 If k = 10 Then WS...
Change the programming language of this snippet from Rust to VB without modifying what it does.
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Function multifactorial(n,d) If n = 0 Then multifactorial = 1 Else For i = n To 1 Step -d If i = n Then multifactorial = n Else multifactorial = multifactorial * i End If Next End If End Function For j = 1 To 5 WScript.StdOut.Write "Degree " & j & ": " For k = 1 To 10 If k = 10 Then WS...
Convert the following code from C++ to Rust, ensuring the logic remains intact.
#include <algorithm> #include <iostream> #include <iterator> int main(void) { for (int g = 1; g < 10; g++) { int v[11], n=0; generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;}); std::cout << std::endl; } return 0; }
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Can you help me rewrite this code in Rust instead of C++, keeping it the same logically?
#include <algorithm> #include <iostream> #include <iterator> int main(void) { for (int g = 1; g < 10; g++) { int v[11], n=0; generate_n(std::ostream_iterator<int>(std::cout, " "), 10, [&]{n++; return v[n]=(g<n)? v[n-g]*n : n;}); std::cout << std::endl; } return 0; }
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Please provide an equivalent version of this Java code in Rust.
public class MultiFact { private static long multiFact(long n, int deg){ long ans = 1; for(long i = n; i > 0; i -= deg){ ans *= i; } return ans; } public static void main(String[] args){ for(int deg = 1; deg <= 5; deg++){ System.out.print("degree " + deg + ":"); for(long n = 1; n <= 10; n++){ ...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Write the same algorithm in Rust as shown in this Go implementation.
package main import "fmt" func multiFactorial(n, k int) int { r := 1 for ; n > 1; n -= k { r *= n } return r } func main() { for k := 1; k <= 5; k++ { fmt.Print("degree ", k, ":") for n := 1; n <= 10; n++ { fmt.Print(" ", multiFactorial(n, k)) } ...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Generate an equivalent Python version of this Rust code.
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
>>> from functools import reduce >>> from operator import mul >>> def mfac(n, m): return reduce(mul, range(n, 0, -m)) >>> for m in range(1, 11): print("%2i: %r" % (m, [mfac(n, m) for n in range(1, 11)])) 1: [1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800] 2: [1, 2, 3, 8, 15, 48, 105, 384, 945, 3840] 3: [1, 2,...
Convert this Java block to Rust, preserving its control flow and logic.
public class MultiFact { private static long multiFact(long n, int deg){ long ans = 1; for(long i = n; i > 0; i -= deg){ ans *= i; } return ans; } public static void main(String[] args){ for(int deg = 1; deg <= 5; deg++){ System.out.print("degree " + deg + ":"); for(long n = 1; n <= 10; n++){ ...
fn multifactorial(n: i32, deg: i32) -> i32 { if n < 1 { 1 } else { n * multifactorial(n - deg, deg) } } fn main() { for i in 1..6 { for j in 1..11 { print!("{} ", multifactorial(j, i)); } println!(""); } }
Produce a functionally identical C# code for the snippet given in Ada.
with Ada.Containers.Doubly_Linked_Lists; with Ada.Text_IO; procedure Traversing is package Char_Lists is new Ada.Containers.Doubly_Linked_Lists (Character); procedure Print (Position : in Char_Lists.Cursor) is begin Ada.Text_IO.Put (Char_Lists.Element (Position)); end Print; My_List : Char_Lists...
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Change the following Ada code into C without altering its purpose.
with Ada.Containers.Doubly_Linked_Lists; with Ada.Text_IO; procedure Traversing is package Char_Lists is new Ada.Containers.Doubly_Linked_Lists (Character); procedure Print (Position : in Char_Lists.Cursor) is begin Ada.Text_IO.Put (Char_Lists.Element (Position)); end Print; My_List : Char_Lists...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Translate this program into C++ but keep the logic exactly as in Ada.
with Ada.Containers.Doubly_Linked_Lists; with Ada.Text_IO; procedure Traversing is package Char_Lists is new Ada.Containers.Doubly_Linked_Lists (Character); procedure Print (Position : in Char_Lists.Cursor) is begin Ada.Text_IO.Put (Char_Lists.Element (Position)); end Print; My_List : Char_Lists...
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Keep all operations the same but rewrite the snippet in Go.
with Ada.Containers.Doubly_Linked_Lists; with Ada.Text_IO; procedure Traversing is package Char_Lists is new Ada.Containers.Doubly_Linked_Lists (Character); procedure Print (Position : in Char_Lists.Cursor) is begin Ada.Text_IO.Put (Char_Lists.Element (Position)); end Print; My_List : Char_Lists...
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Write a version of this Ada function in Java with identical behavior.
with Ada.Containers.Doubly_Linked_Lists; with Ada.Text_IO; procedure Traversing is package Char_Lists is new Ada.Containers.Doubly_Linked_Lists (Character); procedure Print (Position : in Char_Lists.Cursor) is begin Ada.Text_IO.Put (Char_Lists.Element (Position)); end Print; My_List : Char_Lists...
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Write the same algorithm in Python as shown in this Ada implementation.
with Ada.Containers.Doubly_Linked_Lists; with Ada.Text_IO; procedure Traversing is package Char_Lists is new Ada.Containers.Doubly_Linked_Lists (Character); procedure Print (Position : in Char_Lists.Cursor) is begin Ada.Text_IO.Put (Char_Lists.Element (Position)); end Print; My_List : Char_Lists...
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Change the programming language of this snippet from BBC_Basic to C without modifying what it does.
DIM node{pPrev%, pNext%, iData%} DIM a{} = node{}, b{} = node{}, c{} = node{} a.pNext% = b{} a.iData% = 123 b.pPrev% = a{} b.iData% = 789 c.iData% = 456 PROCinsert(a{}, c{}) PRINT "Traverse forwards:" pnode% = a{} REPEAT !(^n...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Write a version of this BBC_Basic function in C# with identical behavior.
DIM node{pPrev%, pNext%, iData%} DIM a{} = node{}, b{} = node{}, c{} = node{} a.pNext% = b{} a.iData% = 123 b.pPrev% = a{} b.iData% = 789 c.iData% = 456 PROCinsert(a{}, c{}) PRINT "Traverse forwards:" pnode% = a{} REPEAT !(^n...
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Port the following code from BBC_Basic to C++ with equivalent syntax and logic.
DIM node{pPrev%, pNext%, iData%} DIM a{} = node{}, b{} = node{}, c{} = node{} a.pNext% = b{} a.iData% = 123 b.pPrev% = a{} b.iData% = 789 c.iData% = 456 PROCinsert(a{}, c{}) PRINT "Traverse forwards:" pnode% = a{} REPEAT !(^n...
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Generate an equivalent Java version of this BBC_Basic code.
DIM node{pPrev%, pNext%, iData%} DIM a{} = node{}, b{} = node{}, c{} = node{} a.pNext% = b{} a.iData% = 123 b.pPrev% = a{} b.iData% = 789 c.iData% = 456 PROCinsert(a{}, c{}) PRINT "Traverse forwards:" pnode% = a{} REPEAT !(^n...
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Convert this BBC_Basic block to Python, preserving its control flow and logic.
DIM node{pPrev%, pNext%, iData%} DIM a{} = node{}, b{} = node{}, c{} = node{} a.pNext% = b{} a.iData% = 123 b.pPrev% = a{} b.iData% = 789 c.iData% = 456 PROCinsert(a{}, c{}) PRINT "Traverse forwards:" pnode% = a{} REPEAT !(^n...
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Generate an equivalent Go version of this BBC_Basic code.
DIM node{pPrev%, pNext%, iData%} DIM a{} = node{}, b{} = node{}, c{} = node{} a.pNext% = b{} a.iData% = 123 b.pPrev% = a{} b.iData% = 789 c.iData% = 456 PROCinsert(a{}, c{}) PRINT "Traverse forwards:" pnode% = a{} REPEAT !(^n...
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Convert the following code from Clojure to C, ensuring the logic remains intact.
(def dl (double-list [:a :b :c :d])) ((juxt seq rseq) dl) (take-while identity (iterate get-next (get-head dl))) (take-while identity (iterate get-prev (get-tail dl)))
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Translate the given Clojure code snippet into C# without altering its behavior.
(def dl (double-list [:a :b :c :d])) ((juxt seq rseq) dl) (take-while identity (iterate get-next (get-head dl))) (take-while identity (iterate get-prev (get-tail dl)))
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Translate the given Clojure code snippet into C++ without altering its behavior.
(def dl (double-list [:a :b :c :d])) ((juxt seq rseq) dl) (take-while identity (iterate get-next (get-head dl))) (take-while identity (iterate get-prev (get-tail dl)))
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Keep all operations the same but rewrite the snippet in Java.
(def dl (double-list [:a :b :c :d])) ((juxt seq rseq) dl) (take-while identity (iterate get-next (get-head dl))) (take-while identity (iterate get-prev (get-tail dl)))
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Translate the given Clojure code snippet into Python without altering its behavior.
(def dl (double-list [:a :b :c :d])) ((juxt seq rseq) dl) (take-while identity (iterate get-next (get-head dl))) (take-while identity (iterate get-prev (get-tail dl)))
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Rewrite this program in Go while keeping its functionality equivalent to the Clojure version.
(def dl (double-list [:a :b :c :d])) ((juxt seq rseq) dl) (take-while identity (iterate get-next (get-head dl))) (take-while identity (iterate get-prev (get-tail dl)))
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Port the following code from D to C with equivalent syntax and logic.
void main() { import std.stdio, std.container, std.range; auto dll = DList!dchar("DCBA"d.dup); dll[].writeln; dll[].retro.writeln; }
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Convert this D block to C#, preserving its control flow and logic.
void main() { import std.stdio, std.container, std.range; auto dll = DList!dchar("DCBA"d.dup); dll[].writeln; dll[].retro.writeln; }
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Write a version of this D function in C++ with identical behavior.
void main() { import std.stdio, std.container, std.range; auto dll = DList!dchar("DCBA"d.dup); dll[].writeln; dll[].retro.writeln; }
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Write the same code in Java as shown below in D.
void main() { import std.stdio, std.container, std.range; auto dll = DList!dchar("DCBA"d.dup); dll[].writeln; dll[].retro.writeln; }
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Produce a language-to-language conversion: from D to Python, same semantics.
void main() { import std.stdio, std.container, std.range; auto dll = DList!dchar("DCBA"d.dup); dll[].writeln; dll[].retro.writeln; }
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Translate the given D code snippet into Go without altering its behavior.
void main() { import std.stdio, std.container, std.range; auto dll = DList!dchar("DCBA"d.dup); dll[].writeln; dll[].retro.writeln; }
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Convert the following code from Delphi to C, ensuring the logic remains intact.
uses system ; type plist = ^List ; List = record data : pointer ; prev : pList ; next : pList ; end; begin while not (pList^.Next = NIL) do pList := pList^.Next ; while not (pList^.prev = NIL) do pList := pList^.prev ; end;
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Keep all operations the same but rewrite the snippet in C#.
uses system ; type plist = ^List ; List = record data : pointer ; prev : pList ; next : pList ; end; begin while not (pList^.Next = NIL) do pList := pList^.Next ; while not (pList^.prev = NIL) do pList := pList^.prev ; end;
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Write a version of this Delphi function in C++ with identical behavior.
uses system ; type plist = ^List ; List = record data : pointer ; prev : pList ; next : pList ; end; begin while not (pList^.Next = NIL) do pList := pList^.Next ; while not (pList^.prev = NIL) do pList := pList^.prev ; end;
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Preserve the algorithm and functionality while converting the code from Delphi to Java.
uses system ; type plist = ^List ; List = record data : pointer ; prev : pList ; next : pList ; end; begin while not (pList^.Next = NIL) do pList := pList^.Next ; while not (pList^.prev = NIL) do pList := pList^.prev ; end;
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Convert this Delphi block to Python, preserving its control flow and logic.
uses system ; type plist = ^List ; List = record data : pointer ; prev : pList ; next : pList ; end; begin while not (pList^.Next = NIL) do pList := pList^.Next ; while not (pList^.prev = NIL) do pList := pList^.prev ; end;
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Write the same code in Go as shown below in Delphi.
uses system ; type plist = ^List ; List = record data : pointer ; prev : pList ; next : pList ; end; begin while not (pList^.Next = NIL) do pList := pList^.Next ; while not (pList^.prev = NIL) do pList := pList^.prev ; end;
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Generate a C translation of this F# snippet without changing its computational steps.
open System.Collections.Generic let first (l: LinkedList<char>) = l.First let last (l: LinkedList<char>) = l.Last let next (l: LinkedListNode<char>) = l.Next let prev (l: LinkedListNode<char>) = l.Previous let traverse g f (ls: LinkedList<char>) = let rec traverse (l: LinkedListNode<char>) = match l with...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Preserve the algorithm and functionality while converting the code from F# to C#.
open System.Collections.Generic let first (l: LinkedList<char>) = l.First let last (l: LinkedList<char>) = l.Last let next (l: LinkedListNode<char>) = l.Next let prev (l: LinkedListNode<char>) = l.Previous let traverse g f (ls: LinkedList<char>) = let rec traverse (l: LinkedListNode<char>) = match l with...
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Produce a language-to-language conversion: from F# to C++, same semantics.
open System.Collections.Generic let first (l: LinkedList<char>) = l.First let last (l: LinkedList<char>) = l.Last let next (l: LinkedListNode<char>) = l.Next let prev (l: LinkedListNode<char>) = l.Previous let traverse g f (ls: LinkedList<char>) = let rec traverse (l: LinkedListNode<char>) = match l with...
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Ensure the translated Java code behaves exactly like the original F# snippet.
open System.Collections.Generic let first (l: LinkedList<char>) = l.First let last (l: LinkedList<char>) = l.Last let next (l: LinkedListNode<char>) = l.Next let prev (l: LinkedListNode<char>) = l.Previous let traverse g f (ls: LinkedList<char>) = let rec traverse (l: LinkedListNode<char>) = match l with...
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Rewrite the snippet below in Python so it works the same as the original F# code.
open System.Collections.Generic let first (l: LinkedList<char>) = l.First let last (l: LinkedList<char>) = l.Last let next (l: LinkedListNode<char>) = l.Next let prev (l: LinkedListNode<char>) = l.Previous let traverse g f (ls: LinkedList<char>) = let rec traverse (l: LinkedListNode<char>) = match l with...
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Produce a language-to-language conversion: from F# to Go, same semantics.
open System.Collections.Generic let first (l: LinkedList<char>) = l.First let last (l: LinkedList<char>) = l.Last let next (l: LinkedListNode<char>) = l.Next let prev (l: LinkedListNode<char>) = l.Previous let traverse g f (ls: LinkedList<char>) = let rec traverse (l: LinkedListNode<char>) = match l with...
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Port the provided Groovy code into C while preserving the original functionality.
class DoubleLinkedListTraversing { static void main(args) { def linkedList = (1..9).collect() as LinkedList linkedList.each { print it } println() linkedList.reverseEach { print it } } }
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Generate an equivalent C# version of this Groovy code.
class DoubleLinkedListTraversing { static void main(args) { def linkedList = (1..9).collect() as LinkedList linkedList.each { print it } println() linkedList.reverseEach { print it } } }
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Write the same code in C++ as shown below in Groovy.
class DoubleLinkedListTraversing { static void main(args) { def linkedList = (1..9).collect() as LinkedList linkedList.each { print it } println() linkedList.reverseEach { print it } } }
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Translate the given Groovy code snippet into Java without altering its behavior.
class DoubleLinkedListTraversing { static void main(args) { def linkedList = (1..9).collect() as LinkedList linkedList.each { print it } println() linkedList.reverseEach { print it } } }
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Maintain the same structure and functionality when rewriting this code in Python.
class DoubleLinkedListTraversing { static void main(args) { def linkedList = (1..9).collect() as LinkedList linkedList.each { print it } println() linkedList.reverseEach { print it } } }
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Convert this Groovy block to Go, preserving its control flow and logic.
class DoubleLinkedListTraversing { static void main(args) { def linkedList = (1..9).collect() as LinkedList linkedList.each { print it } println() linkedList.reverseEach { print it } } }
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Change the following Haskell code into C without altering its purpose.
main = print . traverse True $ create [10,20,30,40] data DList a = Leaf | Node { prev::(DList a), elt::a, next::(DList a) } create = go Leaf where go _ [] = Leaf go prev (x:xs) = current where current = Node prev x next next = go current xs isLeaf Leaf = T...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Can you help me rewrite this code in C# instead of Haskell, keeping it the same logically?
main = print . traverse True $ create [10,20,30,40] data DList a = Leaf | Node { prev::(DList a), elt::a, next::(DList a) } create = go Leaf where go _ [] = Leaf go prev (x:xs) = current where current = Node prev x next next = go current xs isLeaf Leaf = T...
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Write a version of this Haskell function in C++ with identical behavior.
main = print . traverse True $ create [10,20,30,40] data DList a = Leaf | Node { prev::(DList a), elt::a, next::(DList a) } create = go Leaf where go _ [] = Leaf go prev (x:xs) = current where current = Node prev x next next = go current xs isLeaf Leaf = T...
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Keep all operations the same but rewrite the snippet in Java.
main = print . traverse True $ create [10,20,30,40] data DList a = Leaf | Node { prev::(DList a), elt::a, next::(DList a) } create = go Leaf where go _ [] = Leaf go prev (x:xs) = current where current = Node prev x next next = go current xs isLeaf Leaf = T...
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Rewrite this program in Python while keeping its functionality equivalent to the Haskell version.
main = print . traverse True $ create [10,20,30,40] data DList a = Leaf | Node { prev::(DList a), elt::a, next::(DList a) } create = go Leaf where go _ [] = Leaf go prev (x:xs) = current where current = Node prev x next next = go current xs isLeaf Leaf = T...
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Transform the following Haskell implementation into Go, maintaining the same output and logic.
main = print . traverse True $ create [10,20,30,40] data DList a = Leaf | Node { prev::(DList a), elt::a, next::(DList a) } create = go Leaf where go _ [] = Leaf go prev (x:xs) = current where current = Node prev x next next = go current xs isLeaf Leaf = T...
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Change the following J code into C without altering its purpose.
traverse=:1 :0 work=. result=. conew 'DoublyLinkedListHead' current=. y while. y ~: current=. successor__current do. work=. (work;result;<u data__current) conew 'DoublyLinkedListElement' end. result )
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Translate this program into C# but keep the logic exactly as in J.
traverse=:1 :0 work=. result=. conew 'DoublyLinkedListHead' current=. y while. y ~: current=. successor__current do. work=. (work;result;<u data__current) conew 'DoublyLinkedListElement' end. result )
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Translate the given J code snippet into C++ without altering its behavior.
traverse=:1 :0 work=. result=. conew 'DoublyLinkedListHead' current=. y while. y ~: current=. successor__current do. work=. (work;result;<u data__current) conew 'DoublyLinkedListElement' end. result )
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Write the same algorithm in Java as shown in this J implementation.
traverse=:1 :0 work=. result=. conew 'DoublyLinkedListHead' current=. y while. y ~: current=. successor__current do. work=. (work;result;<u data__current) conew 'DoublyLinkedListElement' end. result )
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Convert this J snippet to Python and keep its semantics consistent.
traverse=:1 :0 work=. result=. conew 'DoublyLinkedListHead' current=. y while. y ~: current=. successor__current do. work=. (work;result;<u data__current) conew 'DoublyLinkedListElement' end. result )
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Rewrite this program in Go while keeping its functionality equivalent to the J version.
traverse=:1 :0 work=. result=. conew 'DoublyLinkedListHead' current=. y while. y ~: current=. successor__current do. work=. (work;result;<u data__current) conew 'DoublyLinkedListElement' end. result )
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Can you help me rewrite this code in C instead of Julia, keeping it the same logically?
mutable struct DLNode{T} value::T pred::Union{DLNode{T}, Nothing} succ::Union{DLNode{T}, Nothing} DLNode(v) = new{typeof(v)}(v, nothing, nothing) end function insertpost(prevnode, node) succ = prevnode.succ prevnode.succ = node node.pred = prevnode node.succ = succ if succ != nothin...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Port the provided Julia code into C# while preserving the original functionality.
mutable struct DLNode{T} value::T pred::Union{DLNode{T}, Nothing} succ::Union{DLNode{T}, Nothing} DLNode(v) = new{typeof(v)}(v, nothing, nothing) end function insertpost(prevnode, node) succ = prevnode.succ prevnode.succ = node node.pred = prevnode node.succ = succ if succ != nothin...
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Write a version of this Julia function in C++ with identical behavior.
mutable struct DLNode{T} value::T pred::Union{DLNode{T}, Nothing} succ::Union{DLNode{T}, Nothing} DLNode(v) = new{typeof(v)}(v, nothing, nothing) end function insertpost(prevnode, node) succ = prevnode.succ prevnode.succ = node node.pred = prevnode node.succ = succ if succ != nothin...
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Convert the following code from Julia to Java, ensuring the logic remains intact.
mutable struct DLNode{T} value::T pred::Union{DLNode{T}, Nothing} succ::Union{DLNode{T}, Nothing} DLNode(v) = new{typeof(v)}(v, nothing, nothing) end function insertpost(prevnode, node) succ = prevnode.succ prevnode.succ = node node.pred = prevnode node.succ = succ if succ != nothin...
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Change the following Julia code into Python without altering its purpose.
mutable struct DLNode{T} value::T pred::Union{DLNode{T}, Nothing} succ::Union{DLNode{T}, Nothing} DLNode(v) = new{typeof(v)}(v, nothing, nothing) end function insertpost(prevnode, node) succ = prevnode.succ prevnode.succ = node node.pred = prevnode node.succ = succ if succ != nothin...
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...
Change the following Julia code into Go without altering its purpose.
mutable struct DLNode{T} value::T pred::Union{DLNode{T}, Nothing} succ::Union{DLNode{T}, Nothing} DLNode(v) = new{typeof(v)}(v, nothing, nothing) end function insertpost(prevnode, node) succ = prevnode.succ prevnode.succ = node node.pred = prevnode node.succ = succ if succ != nothin...
package main import "fmt" type dlNode struct { string next, prev *dlNode } type dlList struct { head, tail *dlNode } func (list *dlList) String() string { if list.head == nil { return fmt.Sprint(list.head) } r := "[" + list.head.string for p := list.head.next; p != nil; p = p.nex...
Rewrite this program in C while keeping its functionality equivalent to the Lua version.
List.iterateForward = function(self) local function iter(self, node) if node then return node.next else return self.head end end return iter, self, nil end List.iterateReverse = function(self) local function iter(self, node) if node then return node.prev else return self.tail end end return iter,...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct sListEntry { const char *value; struct sListEntry *next; struct sListEntry *prev; } *ListEntry, *LinkedList; typedef struct sListIterator{ ListEntry link; LinkedList head; } *LIterator; LinkedList NewList() { ListEntr...
Please provide an equivalent version of this Lua code in C#.
List.iterateForward = function(self) local function iter(self, node) if node then return node.next else return self.head end end return iter, self, nil end List.iterateReverse = function(self) local function iter(self, node) if node then return node.prev else return self.tail end end return iter,...
using System; using System.Collections.Generic; namespace RosettaCode.DoublyLinkedList { internal static class Program { private static void Main() { var list = new LinkedList<char>("hello"); var current = list.First; do { Console...
Convert this Lua snippet to C++ and keep its semantics consistent.
List.iterateForward = function(self) local function iter(self, node) if node then return node.next else return self.head end end return iter, self, nil end List.iterateReverse = function(self) local function iter(self, node) if node then return node.prev else return self.tail end end return iter,...
#include <iostream> #include <list> int main () { std::list<int> numbers {1, 5, 7, 0, 3, 2}; for(const auto& i: numbers) std::cout << i << ' '; std::cout << '\n'; }
Maintain the same structure and functionality when rewriting this code in Java.
List.iterateForward = function(self) local function iter(self, node) if node then return node.next else return self.head end end return iter, self, nil end List.iterateReverse = function(self) local function iter(self, node) if node then return node.prev else return self.tail end end return iter,...
package com.rosettacode; import java.util.LinkedList; import java.util.stream.Collectors; import java.util.stream.IntStream; public class DoubleLinkedListTraversing { public static void main(String[] args) { final LinkedList<String> doubleLinkedList = IntStream.range(1, 10) .mapToObj(Strin...
Convert this Lua block to Python, preserving its control flow and logic.
List.iterateForward = function(self) local function iter(self, node) if node then return node.next else return self.head end end return iter, self, nil end List.iterateReverse = function(self) local function iter(self, node) if node then return node.prev else return self.tail end end return iter,...
class List: def __init__(self, data, next=None, prev=None): self.data = data self.next = next self.prev = prev def append(self, data): if self.next == None: self.next = List(data, None, self) return self.next else: return self.next.app...