Skip to content

Instantly share code, notes, and snippets.

View RuiGeng's full-sized avatar

Rui Geng RuiGeng

  • Toronto, Ontario, Canada
View GitHub Profile
@RuiGeng
RuiGeng / Main.cs
Created November 14, 2017 21:49
[C# Programming Interview Questions] How to merge two sorted linked list. Solution 3
void Main()
{
var firstNode1 = new ListNode(1);
var firstNode2 = new ListNode(3);
var firstNode3 = new ListNode(5);
var firstNode4 = new ListNode(7);
var firstNode5 = new ListNode(9);
firstNode1.next = firstNode2;
firstNode2.next = firstNode3;
firstNode3.next = firstNode4;
@RuiGeng
RuiGeng / Main.cs
Created November 14, 2017 21:27
[C# Programming Interview Questions] How to merge two sorted linked list. Solution 2
void Main()
{
var firstNode1 = new ListNode(1);
var firstNode2 = new ListNode(3);
var firstNode3 = new ListNode(5);
var firstNode4 = new ListNode(7);
var firstNode5 = new ListNode(9);
firstNode1.next = firstNode2;
firstNode2.next = firstNode3;
firstNode3.next = firstNode4;
@RuiGeng
RuiGeng / Main.cs
Last active November 14, 2017 21:27
[C# Programming Interview Questions] How to merge two sorted linked list. Solution 1
void Main()
{
LinkedList linkedList1 = new LinkedList();
linkedList1.push(1);
linkedList1.push(3);
linkedList1.push(5);
linkedList1.push(7);
linkedList1.push(9);
LinkedList linkedList2 = new LinkedList();
@RuiGeng
RuiGeng / Main.cs
Last active November 10, 2017 19:00
[C# Programming Interview Questions] How to detect a cycle in singly linked list?
void Main()
{
LinkedList linkedList = new LinkedList();
linkedList.push(20);
linkedList.push(4);
linkedList.push(15);
linkedList.push(10);
Console.WriteLine(linkedList.DetectCycleVersion2(linkedList.head));
/*Create loop for testing */
linkedList.head.Next.Next.Next.Next = linkedList.head;
@RuiGeng
RuiGeng / Main.cs
Last active October 31, 2017 13:34
[C# Programming Interview Questions] Given an unsorted array which has a number in the majority (a number appears more than 50% in the array), find that number?
void Main()
{
List<int> numbers = new List<int> {8,7,6,5,6,6,6,6,6,2,8,7,6,5,6,6};
int number = numbers.GetMajorityNumber();
Console.WriteLine($@"The Majority Number is {number}");
}
/// <summary>
/// Given an unsorted array which has a number in the majority
/// (a number appears more than 50% in the array), find that number?
@RuiGeng
RuiGeng / Main.cs
Created October 30, 2017 16:29
[C# Extension Method] Extension Formatename method for string example
void Main()
{
Console.WriteLine(Person.FullName);
Person.FullName.FormateName(
s =>
{
string outS = "";
foreach (var c in s)
{
@RuiGeng
RuiGeng / ReactiveListExample.cs
Last active September 5, 2017 21:25
[C# Reactive List Example] Using ReactiveList to track a property change in an object list
void Main()
{
IReactiveList<ExplorerTitleBarItem> ExplorerTitleBarItems;
ExplorerTitleBarItems = new ReactiveList<ExplorerTitleBarItem>()
{
new ExplorerTitleBarItem("Documnet Viewer"),
new ExplorerTitleBarItem("Bookmarks"),
new ExplorerTitleBarItem("Clipboard")
};
@RuiGeng
RuiGeng / Compare.cs
Last active September 1, 2017 18:07
[C# Compare List of objects] Compare two list of objects are equal
void Main()
{
var matrix1 = new[] {
new Matrix { Row = "0", Column = "0", Value = 1 },
new Matrix { Row = "1", Column = "1", Value = 2 }
};
var matrix2 = new[] {
new Matrix { Row = "0", Column = "0", Value = 1 },
new Matrix { Row = "1", Column = "1", Value = 2 }
@RuiGeng
RuiGeng / BusySpinner.cs
Last active July 18, 2017 14:46
[C# Busyspinner] Can change spinner color and start/stop spin
public class BusySpinner
{
private Brush brush;
public Canvas BusySpinnerCanvas { get;}
private DispatcherTimer animationTimer;
const int Steps = 16;
public BusySpinner(Brush brush)
{
this.brush = brush;