-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathSkipListNode.cs
62 lines (54 loc) · 1.53 KB
/
SkipListNode.cs
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
using System;
namespace DataStructures.Lists
{
public class SkipListNode<T> : IComparable<SkipListNode<T>> where T : IComparable<T>
{
/// <summary>
/// Instance variables
/// </summary>
private T _value;
private SkipListNode<T>[] _forwards;
/// <summary>
/// CONSTRUCTORS
/// </summary>
public SkipListNode(T value, int level)
{
if (level < 0)
throw new ArgumentOutOfRangeException("Invalid value for level.");
Value = value;
Forwards = new SkipListNode<T>[level];
}
/// <summary>
/// Get and set node's value
/// </summary>
public virtual T Value
{
get { return this._value; }
private set { this._value = value; }
}
/// <summary>
/// Get and set node's forwards links
/// </summary>
public virtual SkipListNode<T>[] Forwards
{
get { return this._forwards; }
private set { this._forwards = value; }
}
/// <summary>
/// Return level of node.
/// </summary>
public virtual int Level
{
get { return Forwards.Length; }
}
/// <summary>
/// IComparable method implementation
/// </summary>
public int CompareTo(SkipListNode<T> other)
{
if (other == null)
return -1;
return this.Value.CompareTo(other.Value);
}
}
}