You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/code/projects/CList/CList/CList.cs
+26-25Lines changed: 26 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -36,18 +36,18 @@ public void AddF(T dataP)
36
36
first=newCell(dataP,first);
37
37
}
38
38
39
-
// We will frequently test if
40
-
// a CList is empty, so we introduce
41
-
// a method for that:
42
-
publicboolIsEmpty()
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
+
publicboolIsEmpty()
43
+
{
44
+
return(first==null);
45
+
}
46
46
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
-
publicvoidAddL(TdataP)
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
+
publicvoidAddL(TdataP)
51
51
{
52
52
if(IsEmpty())
53
53
AddF(dataP);
@@ -64,6 +64,7 @@ public void AddL(T dataP)
64
64
cCell.Next=newCell(dataP,null);
65
65
}
66
66
}
67
+
67
68
// Property for the size of the CList.
68
69
publicintSize
69
70
{
@@ -89,6 +90,7 @@ public int Size
89
90
returnsize;
90
91
}
91
92
}
93
+
92
94
// We can implement a ToString method
93
95
// "the usual way", using a loop
94
96
// similar to the one in AddL:
@@ -98,21 +100,21 @@ public int Size
98
100
publicoverridestringToString()
99
101
{
100
102
stringreturned="———";
101
-
// Line above the table
103
+
// Line above the table
102
104
for(inti=0;i<Size;i++)
103
105
{
104
106
returned+="————";
105
107
}
106
108
returned+="\n| ";
107
-
// Content of the CList
109
+
// Content of the CList
108
110
CellcCell=first;
109
111
while(cCell!=null)
110
112
{
111
113
returned+=$"{cCell.Data} | ";
112
114
cCell=cCell.Next;
113
115
}
114
116
returned+="\n———";
115
-
// Line below the table
117
+
// Line below the table
116
118
for(inti=0;i<Size;i++)
117
119
{
118
120
returned+="————";
@@ -330,15 +332,14 @@ private int Count(T dataP, Cell pTmp)
330
332
return0+Count(dataP,pTmp.Next);
331
333
}
332
334
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.
0 commit comments