-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDequeViewModel.cs
More file actions
67 lines (52 loc) · 1.71 KB
/
DequeViewModel.cs
File metadata and controls
67 lines (52 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.ComponentModel;
namespace Immutable_Deque_visualization
{
public class DequeViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
public IDeque<string> Deque { get; protected set; }
public string NewNodeValue { get; set; }
public RelayCommand EnqueueLeftCommand { get; protected set; }
public RelayCommand EnqueueRightCommand { get; protected set; }
public RelayCommand DequeueLeftCommand { get; protected set; }
public RelayCommand DequeueRightCommand { get; protected set; }
public DequeViewModel()
{
Deque = Deque<string>.Empty;
EnqueueLeftCommand = new RelayCommand(EnqueueLeft);
EnqueueRightCommand = new RelayCommand(EnqueueRight);
DequeueLeftCommand = new RelayCommand(DequeueLeft);
DequeueRightCommand = new RelayCommand(DequeueRight);
}
public void EnqueueLeft()
{
Deque = Deque.EnqueueLeft(NewNodeValue);
DequeChanged();
}
public void EnqueueRight()
{
Deque = Deque.EnqueueRight(NewNodeValue);
DequeChanged();
}
void DequeueLeft()
{
if (!Deque.IsEmpty)
{
Deque = Deque.DequeueLeft();
DequeChanged();
}
}
void DequeueRight()
{
if (!Deque.IsEmpty)
{
Deque = Deque.DequeueRight();
DequeChanged();
}
}
void DequeChanged()
{
PropertyChanged(this, new PropertyChangedEventArgs("Deque"));
}
}
}