Skip to content

Commit e131505

Browse files
committed
Remove redundant totalcount
Adjust null handling for previous in Bag.Add function
1 parent c720f4d commit e131505

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

DataStructures/Bag/Bag.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ public void Add(T item)
5757
current = current.Next;
5858
}
5959

60-
// Item not found, add it
61-
if (previous != null)
62-
{
63-
previous.Next = new BagNode<T>(item);
64-
totalCount++;
65-
}
60+
previous!.Next = new BagNode<T>(item);
61+
totalCount++;
6662
}
6763

6864
/// <summary>
@@ -79,11 +75,6 @@ public void Clear()
7975
/// </summary>
8076
public int Count => totalCount;
8177

82-
/// <summary>
83-
/// Gets the total number of items in the bag, including all multiplicities.
84-
/// </summary>
85-
public int TotalCount => totalCount;
86-
8778
/// <summary>
8879
/// Returns a boolean indicating whether the bag is empty.
8980
/// </summary>

DataStructures/Bag/BagNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ public class BagNode<T>(T item)
1010

1111
public int Multiplicity { get; set; } = 1;
1212

13-
public BagNode<T>? Next { get; set; } = null;
13+
public BagNode<T>? Next { get; set; }
1414
}

0 commit comments

Comments
 (0)