Skip to content

Commit 6e0a140

Browse files
committed
Reworked buttons into a scroll viewer and stack panel which scale with the height of the window. Window now can be resized and the bars will be regenerated accordingly. Minimum height and width are set to prevent overlapping of elements.
Added Double Selection Sort. Added user options to change how the array values are assigned: linear, random, exponential and logarithm. These are the main types you would want to visualise but at some point I could add others e.g. x^2, x^3, sin(x)...
1 parent c9b478c commit 6e0a140

10 files changed

+3920
-51
lines changed

Sorting Algorithms/MainWindow.xaml

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,64 @@
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:local="clr-namespace:Sorting_Algorithms"
77
mc:Ignorable="d"
8-
Title="MainWindow" Height="550" Width="1000" ResizeMode="NoResize" WindowStartupLocation="CenterScreen">
8+
SizeChanged="Window_SizeChanged"
9+
Title="Sorting Algorithms" Height="600" Width="860" ResizeMode="CanResize" WindowStartupLocation="CenterScreen">
910
<Canvas Name="myCanvas">
10-
<Button Name="BubbleBtn" Content="Bubble Sort" Margin="10" Width="100" Height="25" Click="BubbleBtn_Click"></Button>
11-
<Button Name="CocktailBtn" Content="Cocktail Shaker" Canvas.Top="30" Margin="10" Width="100" Height="25" Click="CocktailBtn_Click"></Button>
12-
<Button Name="CombBtn" Content="Comb Sort" Margin="10" Canvas.Top="60" Width="100" Height="25" Click="CombBtn_Click"></Button>
13-
14-
<Button Name="InsertBtn" Content="Insertion Sort" Margin="10" Canvas.Top="90" Width="100" Height="25" Click="InsertBtn_Click"></Button>
15-
<Button Name="ShellBtn" Content="Shell Sort" Margin="10" Canvas.Top="120" Width="100" Height="25" Click="ShellBtn_Click"></Button>
16-
<Button Name="BinaryInsertBtn" Content="Binary Insertion" Margin="10" Canvas.Top="150" Width="100" Height="25" Click="BinaryInsertBtn_Click"></Button>
17-
18-
<Button Name="SelectBtn" Content="Selection Sort" Margin="10" Canvas.Top="180" Width="100" Height="25" Click="SelectBtn_Click"></Button>
19-
<Button Name="QuickLomutoBtn" Content="Quick (Lomuto)" Margin="10" Canvas.Top="210" Width="100" Height="25" Click="QuickLomutoBtn_Click"></Button>
20-
<Button Name="QuickHoareBtn" Content="Quick (Hoare)" Margin="10" Canvas.Top="270" Width="100" Height="25" Click="QuickHoareBtn_Click"></Button>
21-
<Button Name="QuickLomutoMedianBtn" Content="Quick (Median)" Margin="10" Canvas.Top="240" Width="100" Height="25" Click="QuickLomutoMedianBtn_Click"></Button>
22-
23-
<Button Name="ShuffleBtn" Content="Shuffle" Canvas.Left="110" Height="25" Margin="10" Width="100" Click="ShuffleBtn_Click"></Button>
24-
<Button Name="ReverseBtn" Content="Reverse Order" Canvas.Left="110" Canvas.Top="30" Height="25" Margin="10" Width="100" Click="ReverseBtn_Click"></Button>
25-
26-
<CheckBox Name="RandomValueCheck" Content="Random Values" Canvas.Left="240" Canvas.Top="45" Checked="RandomValueCheck_Checked" Unchecked="RandomValueCheck_Checked"></CheckBox>
27-
28-
<Button Name="StopBtn" Foreground="Red" IsEnabled="False" Content="STOP" Canvas.Right="10" Canvas.Top="10" Height="25" Width="100" Click="StopBtn_Click"></Button>
29-
<Label Name="ComparesLbl" Content="Comparisons: " Canvas.Right="180" Canvas.Top="10"></Label>
30-
<Label Name="SwapsLbl" Content="Swaps: " Canvas.Right="180" Canvas.Top="35"></Label>
31-
32-
<Label Name="CountLbl" Content="Elements: " Canvas.Left="225" Margin="10"></Label>
33-
<Slider Name="BarCount" Minimum="10" Maximum="200" Canvas.Left="325" Margin="10" Height="25" Canvas.Top="3" Width="300" Value="40" ValueChanged="BarCount_ValueChanged" VerticalContentAlignment="Center"></Slider>
11+
12+
<ScrollViewer Name="SortButtonsScroller" Height="568" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Disabled">
13+
<StackPanel>
14+
<GroupBox Name="BubbleGroup" Header="Bubble Sorts" Margin="10" FontStyle="Italic" BorderBrush="Gray" BorderThickness="2">
15+
<StackPanel Margin="2">
16+
<Button Name="BubbleBtn" Content="Bubble Sort" Margin="2" Width="100" Height="25" Click="BubbleBtn_Click" ToolTip="Standard Bubble Sort with Early Exit"></Button>
17+
<Button Name="CocktailBtn" Content="Cocktail Shaker" Margin="2" Width="100" Height="25" Click="CocktailBtn_Click" ToolTip="Bubble Sort which alternates between moving up and down the array"></Button>
18+
<Button Name="CombBtn" Content="Comb Sort" Margin="2" Width="100" Height="25" Click="CombBtn_Click" ToolTip="Bubble Sort comparing elements separated by a decreasng interval"></Button>
19+
</StackPanel>
20+
</GroupBox>
21+
22+
<GroupBox Name="InsertionGroup" Header="Insertion Sorts" Margin="10" FontStyle="Italic" BorderBrush="Gray" BorderThickness="2" Canvas.Top="120">
23+
<StackPanel Margin="2">
24+
<Button Name="InsertBtn" Content="Insertion Sort" Margin="2" Canvas.Top="90" Width="100" Height="25" Click="InsertBtn_Click" ToolTip="Standard Insertion Sort with Early Exit"></Button>
25+
<Button Name="ShellBtn" Content="Shell Sort" Margin="2" Canvas.Top="120" Width="100" Height="25" Click="ShellBtn_Click" ToolTip="Shell-Optimised Insertion Sort where initial passes sort array in sub-lists"></Button>
26+
<Button Name="BinaryInsertBtn" Content="Binary Insertion" Margin="2" Canvas.Top="150" Width="100" Height="25" Click="BinaryInsertBtn_Click" ToolTip="Insertion Sort, using Binary Search to position elements"></Button>
27+
</StackPanel>
28+
</GroupBox>
29+
30+
<GroupBox Name="SelectionGroup" Header="Selection Sort" Margin="10" FontStyle="Italic" BorderBrush="Gray" BorderThickness="2" Canvas.Top="240">
31+
<StackPanel Margin="2">
32+
<Button Name="SelectBtn" Content="Selection Sort" Margin="2" Width="100" Height="25" Click="SelectBtn_Click" ToolTip="Standard Selection Sort with Early Exit"/>
33+
<Button Name="DoubleSelectBtn" Content="Double Selection" Margin="2" Width="100" Height="25" Click="DoubleSelectBtn_Click" ToolTip="Selection Sort which finds minimum and maximum on each pass"/>
34+
</StackPanel>
35+
</GroupBox>
36+
37+
<GroupBox Name="QuickSortGroup" Header="Quick Sort" Margin="10" FontStyle="Italic" BorderBrush="Gray" BorderThickness="2" Canvas.Top="300">
38+
<StackPanel Margin="2">
39+
<Button Name="QuickLomutoBtn" Content="Quick (Lomuto)" Margin="2" Canvas.Top="210" Width="100" Height="25" Click="QuickLomutoBtn_Click" ToolTip="Quick Sort using Lomuto Partitioning (pivot at end)"></Button>
40+
<Button Name="QuickHoareBtn" Content="Quick (Hoare)" Margin="2" Canvas.Top="270" Width="100" Height="25" Click="QuickHoareBtn_Click" ToolTip="Lomuto Quick Sort with median Partitioning (pivot in median)"></Button>
41+
<Button Name="QuickLomutoMedianBtn" Content="Quick (Median)" Margin="2" Canvas.Top="240" Width="100" Height="25" Click="QuickLomutoMedianBtn_Click" ToolTip="Quick Sort with Hoare Partitioning (pivot in midpoint)"></Button>
42+
</StackPanel>
43+
</GroupBox>
44+
</StackPanel>
45+
</ScrollViewer>
46+
47+
<Button Name="ShuffleBtn" Content="Shuffle" Canvas.Right="10" Height="25" Width="100" Click="ShuffleBtn_Click" Canvas.Top="70" ToolTip="Randomly order the current array"/>
48+
<Button Name="ReverseBtn" Content="Reverse Order" Canvas.Right="120" Canvas.Top="70" Height="25" Width="100" Click="ReverseBtn_Click" ToolTip="Reverse the current array order"/>
49+
50+
<Button Name="StopBtn" BorderThickness="3" FontSize="16" FontFamily="Futura" Foreground="Red" IsEnabled="False" Content="STOP" Canvas.Right="10" Canvas.Top="10" Height="50" Width="100" Click="StopBtn_Click"></Button>
51+
<Label Name="ComparesLbl" Content="Comparisons: " Canvas.Right="115" Width="140" Canvas.Top="10" ToolTip="Number of comparisons made between array elements during this sort"></Label>
52+
<Label Name="SwapsLbl" Content="Swaps: " Width="105" Canvas.Right="114" Canvas.Top="35" ToolTip="Number of swaps made to array during this sort"></Label>
53+
54+
<Label Name="CountLbl" Content="Elements: " Canvas.Left="330" Canvas.Top="70" Width="100"/>
55+
<Slider Name="BarCount" Minimum="10" Maximum="200" Canvas.Left="329" Height="25" Canvas.Top="13" Width="252" Value="40" ValueChanged="BarCount_ValueChanged" VerticalContentAlignment="Center"/>
56+
<Label Name="BarExpLbl" Content="Drag the slider to change the size of the array" Canvas.Left="329" Canvas.Top="35"></Label>
3457
<Label Name="TimeLbl" Content="Time Elapsed: " Canvas.Left="110" Canvas.Top="60" Margin="10" Visibility="Hidden"></Label>
58+
59+
<GroupBox Margin="10" Canvas.Left="160" BorderBrush="Gray" BorderThickness="2" Header="Data Styles">
60+
<StackPanel Name="DataStyleCheckBoxes" Margin="2" Width="135">
61+
<RadioButton Name="LinearValueCheck" IsChecked="True" Margin="2" Content="Linear Values" Canvas.Left="175" Canvas.Top="42" Checked="LinearValueCheck_Checked" ToolTip="Check to use linear heights"></RadioButton>
62+
<RadioButton Name="RandomValueCheck" Margin="2" Content="Random Values" Canvas.Left="175" Canvas.Top="42" Checked="RandomValueCheck_Checked" ToolTip="Check to use random heights"></RadioButton>
63+
<RadioButton Name="ExpValueCheck" Margin="2" Content="Exponential Values" Canvas.Left="175" Canvas.Top="42" Checked="ExpValueCheck_Checked" ToolTip="Check to use exponential heights"></RadioButton>
64+
<RadioButton Name="LogValueCheck" Margin="2" Content="Logarithm Values" Canvas.Left="175" Canvas.Top="42" Checked="LogValueCheck_Checked" ToolTip="Check to use log (base e) heights"></RadioButton>
65+
</StackPanel>
66+
</GroupBox>
3567
</Canvas>
3668
</Window>

0 commit comments

Comments
 (0)