Skip to content

Commit 06e7d48

Browse files
committed
Tidied up code.
1 parent 1f76476 commit 06e7d48

File tree

7 files changed

+222
-182
lines changed

7 files changed

+222
-182
lines changed

source/code/projects/CList/CList/CList.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ public void AddF(T dataP)
3636
first = new Cell(dataP, first);
3737
}
3838

39-
// We will frequently test if
40-
// a CList is empty, so we introduce
41-
// a method for that:
42-
public bool IsEmpty()
43-
{
44-
return (first == null);
45-
}
39+
// We will frequently test if
40+
// a CList is empty, so we introduce
41+
// a method for that:
42+
public bool IsEmpty()
43+
{
44+
return (first == null);
45+
}
4646

47-
// A method to add a cell at the end
48-
// of the CList (to the right).
49-
// We call it AddL for 'Add Last'.
50-
public void AddL(T dataP)
47+
// A method to add a cell at the end
48+
// of the CList (to the right).
49+
// We call it AddL for 'Add Last'.
50+
public void AddL(T dataP)
5151
{
5252
if (IsEmpty())
5353
AddF(dataP);
@@ -64,6 +64,7 @@ public void AddL(T dataP)
6464
cCell.Next = new Cell(dataP, null);
6565
}
6666
}
67+
6768
// Property for the size of the CList.
6869
public int Size
6970
{
@@ -89,6 +90,7 @@ public int Size
8990
return size;
9091
}
9192
}
93+
9294
// We can implement a ToString method
9395
// "the usual way", using a loop
9496
// similar to the one in AddL:
@@ -98,21 +100,21 @@ public int Size
98100
public override string ToString()
99101
{
100102
string returned = "———";
101-
// Line above the table
103+
// Line above the table
102104
for (int i = 0; i < Size; i++)
103105
{
104106
returned += "————";
105107
}
106108
returned += "\n| ";
107-
// Content of the CList
109+
// Content of the CList
108110
Cell cCell = first;
109111
while (cCell != null)
110112
{
111113
returned += $"{cCell.Data} | ";
112114
cCell = cCell.Next;
113115
}
114116
returned += "\n———";
115-
// Line below the table
117+
// Line below the table
116118
for (int i = 0; i < Size; i++)
117119
{
118120
returned += "————";
@@ -330,15 +332,14 @@ private int Count(T dataP, Cell pTmp)
330332
return 0 + Count(dataP, pTmp.Next);
331333
}
332334

333-
/* Some other methods that can be implemented are:
334-
- ToArray(), that returns an array containing the values held in the calling object,
335-
- CopyTo(int startP, int endP), that returns a CList object containing the elements between indices startP (included) and endP (excluded) in the calling object, and throw an error if the range is outside the calling object's limits,
336-
- FromArray(T[] arrayP) that appends to the calling object the value held in the arrayP parameter,
337-
- IndexCListOf(T elemP) returns a CList containing all the indices where the value elemP is stored in the calling object,
338-
- Remove(int startP, int endP) that removes all the cells between indices startP (included) and endP (excluded) in the calling object, and throw an error if the range is outside the calling object's limits,
339-
- Reverse(int startP, int endP) that reverse the order of all the cells between indices startP (included) and endP (excluded) in the calling object, and throw an error if the range is outside the calling object's limits,
340-
- Concat(CList<T> clistP) that append to the end of the calling object the elements in the CList clistP,
341-
- Insert(T elemP, int indexP) that insert at indexP the elemP if the calling object is of size at least indexP, and throw an error otherwise.
342-
*/
343-
335+
/* Some other methods that can be implemented are:
336+
- ToArray(), that returns an array containing the values held in the calling object,
337+
- CopyTo(int startP, int endP), that returns a CList object containing the elements between indices startP (included) and endP (excluded) in the calling object, and throw an error if the range is outside the calling object's limits,
338+
- FromArray(T[] arrayP) that appends to the calling object the value held in the arrayP parameter,
339+
- IndexCListOf(T elemP) returns a CList containing all the indices where the value elemP is stored in the calling object,
340+
- Remove(int startP, int endP) that removes all the cells between indices startP (included) and endP (excluded) in the calling object, and throw an error if the range is outside the calling object's limits,
341+
- Reverse(int startP, int endP) that reverse the order of all the cells between indices startP (included) and endP (excluded) in the calling object, and throw an error if the range is outside the calling object's limits,
342+
- Concat(CList<T> clistP) that append to the end of the calling object the elements in the CList clistP,
343+
- Insert(T elemP, int indexP) that insert at indexP the elemP if the calling object is of size at least indexP, and throw an error otherwise.
344+
*/
344345
}

source/code/projects/CList/CList/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
class Program
44
{
55
static void Main(string[] args)
6-
{
6+
{
77
/* First example. */
88
CList<int> myList1 = new CList<int>();
9-
Console.WriteLine(myList1);
9+
Console.WriteLine(myList1);
1010
myList1.AddL(1);
1111
myList1.AddL(5);
1212
myList1.AddL(2);

source/code/projects/CList_Intro/CList/CList.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public CList()
1010
{
1111
first = null;
1212
}
13+
1314
// A Cell is itself two things:
1415
// - An element of data (of type T),
1516
// - Another cell, containing the next element of data.
@@ -33,6 +34,6 @@ public void AddF(T dataP)
3334
{
3435
first = new Cell(dataP, first);
3536
}
36-
// The updated CList starts with a cell holding dataP and
37+
// The updated CList starts with a cell holding dataP and
3738
// a Cell referencing the previous first cell.
3839
}

source/code/projects/FileTruncate/FileTruncate/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ static void Main()
3333
// End solution
3434
}
3535
}
36-

0 commit comments

Comments
 (0)