-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1861056
commit 1dacebe
Showing
12 changed files
with
4,718 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
namespace System.Collections.Generic | ||
{ | ||
/// <summary> | ||
/// Provides extension methods for LinkedList. | ||
/// </summary> | ||
public static class LinkedListExtensions | ||
{ | ||
/// <summary> | ||
/// Finds the next node after the given node that contains the specified value. | ||
/// </summary> | ||
/// <typeparam name="T">The type of value in the linked list.</typeparam> | ||
/// <param name="list">The linked list.</param> | ||
/// <param name="node">The node after which to search for the value in the linked list, or <c>null</c> to search from the beginning.</param> | ||
/// <param name="value">The value to locate in the linked list.</param> | ||
/// <returns>The first node after the given node that contains the specified value, if found; otherwise, <c>null</c>.</returns> | ||
public static LinkedListNode<T> FindNext<T>(this LinkedList<T> list, LinkedListNode<T> node, T value) | ||
{ | ||
if (list == null) | ||
{ | ||
throw new ArgumentNullException("list"); | ||
} | ||
|
||
if (node == null) | ||
{ | ||
return list.Find(value); | ||
} | ||
|
||
if (list != node.List) | ||
{ | ||
throw new ArgumentException("The list does not contain the given node."); | ||
} | ||
|
||
EqualityComparer<T> comparer = EqualityComparer<T>.Default; | ||
|
||
// Skip the given node. | ||
node = node.Next; | ||
while (node != null) | ||
{ | ||
if (value != null) | ||
{ | ||
if (comparer.Equals(node.Value, value)) | ||
{ | ||
return node; | ||
} | ||
} | ||
else if (node.Value == null) | ||
{ | ||
return node; | ||
} | ||
node = node.Next; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Finds the previous node before the given node that contains the specified value. | ||
/// </summary> | ||
/// <typeparam name="T">The type of value in the linked list.</typeparam> | ||
/// <param name="list">The linked list.</param> | ||
/// <param name="node">The node before which to search for the value in the linked list, or <c>null</c> to search from the end.</param> | ||
/// <param name="value">The value to locate in the linked list.</param> | ||
/// <returns>The first node before the given node that contains the specified value, if found; otherwise, <c>null</c>.</returns> | ||
public static LinkedListNode<T> FindPrevious<T>(this LinkedList<T> list, LinkedListNode<T> node, T value) | ||
{ | ||
if (list == null) | ||
{ | ||
throw new ArgumentNullException("list"); | ||
} | ||
|
||
if (node == null) | ||
{ | ||
return list.FindLast(value); | ||
} | ||
|
||
if (list != node.List) | ||
{ | ||
throw new ArgumentException("The list does not contain the given node."); | ||
} | ||
|
||
EqualityComparer<T> comparer = EqualityComparer<T>.Default; | ||
|
||
// Skip the given node. | ||
node = node.Previous; | ||
while (node != null) | ||
{ | ||
if (value != null) | ||
{ | ||
if (comparer.Equals(node.Value, value)) | ||
{ | ||
return node; | ||
} | ||
} | ||
else if (node.Value == null) | ||
{ | ||
return node; | ||
} | ||
node = node.Previous; | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
<Window x:Class="PixelCircle.MainWindow" | ||
<Window | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:PixelCircle" | ||
xmlns:Controls="clr-namespace:System.Windows.Controls" x:Class="PixelCircle.MainWindow" | ||
mc:Ignorable="d" | ||
Title="MainWindow" Height="350" Width="525"> | ||
Title="PixelCircle" Height="380" Width="680"> | ||
<Grid> | ||
|
||
<DockPanel Name="DockPanel1"> | ||
<StackPanel Width="100px" Margin="10,10,0,10" Panel.ZIndex="99"> | ||
<Label Content="Dimension: " Margin="5,0,5,0"/> | ||
<TextBox x:Name="tb1" Height="23" TextWrapping="Wrap" Text="15" Margin="5,0,5,0"/> | ||
<CheckBox x:Name="checkbox1" Content="Show Grid" Margin="5,5,5,5"/> | ||
<Button Content="Draw" Height="23" Click="Button_Click" Margin="5,5,5,5"/> | ||
</StackPanel> | ||
<Controls:ZoomableCanvas x:Name="Canvas1" Margin="10,10,10,10" Background="AliceBlue" MouseWheel="Canvas1_MouseWheel" MouseDown="Canvas1_MouseDown" MouseMove="Canvas1_MouseMove" MouseUp="Canvas1_MouseUp" MouseLeave="Canvas1_MouseLeave"> | ||
</Controls:ZoomableCanvas> | ||
</DockPanel> | ||
|
||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.