Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RosettaCode {
|
||||
class SortCustomComparator {
|
||||
// Driver program
|
||||
public void CustomSort() {
|
||||
String[] items = { "Here", "are", "some", "sample", "strings", "to", "be", "sorted" };
|
||||
List<String> list = new List<string>(items);
|
||||
|
||||
DisplayList("Unsorted", list);
|
||||
|
||||
list.Sort(CustomCompare);
|
||||
DisplayList("Descending Length", list);
|
||||
|
||||
list.Sort();
|
||||
DisplayList("Ascending order", list);
|
||||
}
|
||||
|
||||
// Custom compare
|
||||
public int CustomCompare(String x, String y) {
|
||||
int result = -x.Length.CompareTo(y.Length);
|
||||
if (result == 0) {
|
||||
result = x.ToLower().CompareTo(y.ToLower());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Output routine
|
||||
public void DisplayList(String header, List<String> theList) {
|
||||
Console.WriteLine(header);
|
||||
Console.WriteLine("".PadLeft(header.Length, '*'));
|
||||
foreach (String str in theList) {
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace RosettaCode
|
||||
{
|
||||
class SortCustomComparator
|
||||
{
|
||||
// Driver program
|
||||
public void CustomSort()
|
||||
{
|
||||
List<string> list = new List<string> { "Here", "are", "some", "sample", "strings", "to", "be", "sorted" };
|
||||
|
||||
DisplayList("Unsorted", list);
|
||||
|
||||
var descOrdered = from l in list
|
||||
orderby l.Length descending
|
||||
select l;
|
||||
DisplayList("Descending Length", descOrdered);
|
||||
|
||||
var ascOrdered = from l in list
|
||||
orderby l
|
||||
select l;
|
||||
DisplayList("Ascending order", ascOrdered);
|
||||
}
|
||||
|
||||
// Output routine
|
||||
public void DisplayList(String header, IEnumerable<string> theList)
|
||||
{
|
||||
Console.WriteLine(header);
|
||||
Console.WriteLine("".PadLeft(header.Length, '*'));
|
||||
foreach (String str in theList)
|
||||
{
|
||||
Console.WriteLine(str);
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue