-
|
Hello, When I run the C code, I get the following compilation error. Should I avoid using # inside nested list elements? |
Beta Was this translation helpful? Give feedback.
Answered by
pfusik
Jun 10, 2026
Replies: 1 comment
-
|
More idiomatic Fusion code would be this: public class Test {
public static List<List<int>()>() Sort(List<List<int>()> input) {
List<List<int>()>() output;
foreach (List<int> inner in input) {
output.Add();
List<int>! sorted = output.Last();
sorted.AddRange(inner);
// simple insertion sort descending
for (int a = 1; a < sorted.Count; a++) {
int key = sorted[a];
int b = a - 1;
while (b >= 0 && sorted[b] < key) {
sorted[b + 1] = sorted[b];
b--;
}
sorted[b + 1] = key;
}
}
return output;
}
public static void Main() {
List<List<int>()>() input;
input.Add();
List<int>! inner1 = input.Last();
inner1.Add(3);
inner1.Add(1);
inner1.Add(2);
input.Add();
List<int>! inner2 = input.Last();
inner2.Add(9);
inner2.Add(7);
inner2.Add(8);
List<List<int>()>() result = Sort(input);
int n = result.Count;
Console.WriteLine($"Number of inner lists: {n}");
// Print first sorted list
Console.Write("First sorted: ");
string sep = "";
foreach (int i in result[0]) {
Console.Write(sep);
Console.Write(i);
sep = ", ";
}
Console.WriteLine();
}
}This unveiled a few issues in |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
c-gummo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More idiomatic Fusion code would be this: