Skip to content

Commit a0e944a

Browse files
ClémentClément
authored andcommitted
Adding Clear and IsEmpty methods for dictionary using chaining.
1 parent 1a7e096 commit a0e944a

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

source/code/projects/Dictionary_chaining/Dictionary/Dictionary.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,26 @@ public void Remove(TKey keyP)
118118

119119
public void Clear()
120120
{
121-
/* Fill me! */
121+
for (int i = 0; i < table.Length; i++)
122+
{
123+
if (table[i] != null) { table[i].Clear(); }
124+
}
122125
}
123126

124127
public bool IsEmpty()
125128
{
126-
127-
/* Fill me! */
128-
return true;
129+
bool empty = true;
130+
for (int i = 0; i < table.Length; i++)
131+
{
132+
if (table[i] != null)
133+
{
134+
if (table[i].Count != 0)
135+
{
136+
empty = false;
137+
}
138+
}
139+
}
140+
return empty;
129141

130142
}
131143
}

0 commit comments

Comments
 (0)