Question 1

For this task you are required to update the solution to the Vector<> class from the Week 3 practical as follows:

  • Rename the Vector<> class to OrderedArray<>;
  • Data must be stored in sorted order;
  • No linear searching or sorting is permitted, the binary search (Workbook Section 8.1.2) and shuffling elements (Workbook Section 1.6.1) in the array must be used instead;
  • You must implement the IList<> interface, requiring the following additional members:
    • public int IndexOf(TYPE item) – returns the index where item is found or -1 if the item is not found;
    • public void Insert(int index, TYPE item) – throws a NotSupportedException;
    • public void RemoveAt(int index) – throws an ArgumentOutOfRangeException if the index is out of bounds, otherwise removes the element stored at the specified index;
    • public void CopyTo(TYPE[] array, int arrayIndex) – throws an ArgumentNullException if array is null, throws an ArgumentOutOfRangeException if arrayIndex is negative, throws an ArgumentException if there is not enough space remaining in the destination array to store all the elements, otherwise copies the stored data to the destination array;
    • public bool IsReadOnly – returns false;
    • public bool Remove(TYPE item) – removes the specified data if found and returns true, otherwise returns false;
  • You must implement an additional method public void Change(TYPE oldValue, TYPE newValue) which replaces the specified oldValue with the specified newValue, maintaining the order in the array;

Question 2

For this task you are required to create a new generic collection HashedList<> which stores data in a hash table declared as follows:

private List[] _HashTable;

The HashedList<> collection must implement the following members:

  • public HashedList(int hashTableSize) – constructor which receives initialises the collection using the specified size for the hash table;
  • public void Add(TYPE data) – stores the specified data into the hash table by using data.GetHashCode() for the hash value and applying modulo division (note that GetHashCode() is provided by Microsoft.Net, you don’t need to write this);
  • public bool Contains(TYPE data) – applies the same hashing technique for the Add method to determine the correct entry in the hash table array then returns true if the data is stored in that hash table entry, otherwise returns false;
  • public void Change(TYPE oldValue, TYPE newValue) – replaces the specified oldValue with the specified newValue, maintaining the integrity of the hash table; and
  • Members as required to implement the IEnumerable<> interface.

Example Output:

Data in OrderedArray:
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
Data in HashedList:
30 20 50 40 80 90 70 100 60 10
1 21 11 51 31 81 71 91 41 61
22 52 42 62 82 32 72 12 92 2
43 33 13 63 73 53 83 93 23 3
24 34 54 4 74 94 14 64 44 84
75 95 35 55 85 25 45 65 5 15
26 86 56 36 66 96 16 46 76 6
87 67 47 37 57 27 17 77 7 97
98 28 8 58 48 38 88 78 18 68
69 9 19 99 89 39 29 79 49 59
Checking to see if data retrieved successfully from OrderedArray... succeeded.
Checking to see if data retrieved successfully from HashedList... succeeded.
Changing the data... done.
Data in OrderedArray:
101 102 103 104 105 106 107 108 109 110
111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130
131 132 133 134 135 136 137 138 139 140
141 142 143 144 145 146 147 148 149 150
151 152 153 154 155 156 157 158 159 160
161 162 163 164 165 166 167 168 169 170
171 172 173 174 175 176 177 178 179 180
181 182 183 184 185 186 187 188 189 190
191 192 193 194 195 196 197 198 199 200
Data in HashedList:
130 120 150 140 180 190 170 200 160 110
101 121 111 151 131 181 171 191 141 161
122 152 142 162 182 132 172 112 192 102
143 133 113 163 173 153 183 193 123 103
124 134 154 104 174 194 114 164 144 184
175 195 135 155 185 125 145 165 105 115
126 186 156 136 166 196 116 146 176 106
187 167 147 137 157 127 117 177 107 197
198 128 108 158 148 138 188 178 118 168
169 109 119 199 189 139 129 179 149 159
Checking to see if data retrieved successfully from OrderedArray... succeeded.
Checking to see if data retrieved successfully from HashedList... succeeded.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.