Skip to content

Commit 7cee230

Browse files
ClémentClément
authored andcommitted
Fixing Dictionary solution.
1 parent bbc68e5 commit 7cee230

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

source/code/projects/SDictionary_solution/SDictionary/Program.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ static void Main(string[] args)
1414
friends.Add("Lora", null);
1515
Console.WriteLine(friends);
1616

17-
Console.WriteLine("Deleted Bob:" + friends.Delete("Bob"));
18-
Console.WriteLine(friends);
19-
Console.WriteLine("Deleted Mary:" + friends.Delete("Mary"));
17+
friends.Add("Bob", null);
18+
friends.Add("Bob", null);
19+
friends.Add("Bob", null);
20+
friends.Add("Bob", null);
21+
friends.Add("Bob", null);
22+
friends.Add("Bob", null);
23+
// At this point the dictionary is full:
2024
Console.WriteLine(friends);
25+
// Uncomment the following to see the program
26+
// enters an infinite loop.
27+
// friends.Add("Bob", null);
2128

2229
// Exhibiting Delete incorrect behavior:
2330
SDictionary demo = new SDictionary(2);

source/solutions/data/dictionary.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ tags:
2626

2727
## Problem
2828

29-
SDictionary_solution
30-
3129
#. Consider the implementation of "simple" dictionary `SDictionary` below:
3230

3331
```{download="./code/projects/SDictionary.zip"}
@@ -80,7 +78,8 @@ SDictionary_solution
8078

8179
<details>
8280
<summary>Solution</summary>
83-
"Lora" would be inserted at index `2`: `10`, `0` and `1` being taken, `Add` goes to the next available index, `2`. This is not expected, since a dictionary should reject
81+
"Lora" would be inserted at index `2`: `10`, `0` and `1` being taken, `Add` goes to the next available index, `2`. This is not expected, since a dictionary should reject entering *two* values with the same key.
82+
</details>
8483

8584
#. Write a `ToString` method for the `SDictionary` class, that returns a `string` containing all the keys and values stored in the dictionary.
8685

@@ -99,8 +98,10 @@ SDictionary_solution
9998
</details>
10099

101100
#. Consider the following `Delete` method:
102-
103-
101+
102+
```{download="./code/projects/SDictionary_solution.zip"}
103+
!include`snippetStart="// Delete method:", snippetEnd="// End of Delete method."` code/projects/SDictionary_solution/SDictionary/SDictionary.cs
104+
```
104105
105106
Complete the series of instructions below such that `demo.Delete(error)` would return `false` even though the string `error` *is* the key of a value present in the `demo` dictionary object.
106107
@@ -121,6 +122,6 @@ SDictionary_solution
121122
The solution is to be in a position where the `error` value is "hidden after" a `null` value:
122123
123124
```{download="./code/projects/SDictionary_solution.zip"}
124-
!include`snippetStart="// Exhibiting Delete incorrect behavior:", snippetEnd="// Done: the program will believe that the "` code/projects/SDictionary_solution/SDictionary/SDictionary.cs
125+
!include`snippetStart="// Exhibiting Delete incorrect behavior:", snippetEnd="// Done: the program will believe that the "` code/projects/SDictionary_solution/SDictionary/Program.cs
125126
```
126127
</details>

0 commit comments

Comments
 (0)