# SIT221 Data Structures and Algorithms Practical Task 1.2

## Practical Task 1.2

**General Instructions**

1. Your task is to extend the functionality of the generic data structure Vector<T>, which you should have already developed as part of the pass task 1.1.

2. Download two C# source code files attached to this task. These files serve as a template for the program that you need to develop. Create a new Microsoft Visual Studio project and import the files, or alternatively, alter the project inherited from task 1.1. Note that file Tester.cs contains a prepared main method important for the purpose of debugging and testing the extended version of the Vector<T> className. Another file, Vector.cs, contains a template of the Vector<T> classNameand gives an example of the following method:

T Find(Func<T, bool> searchCriteria)

Searches for an element that matches the conditions defined by the specified delegate searchCriteria, and returns the first occurrence within the entire Vector<T>. If there is no element matching the search criteria, the method returns the default value for type T. It thows ArgumentNullException when searchCriteria is null.

The given prototype of the Vector<T> classNameshould help you with development of the functionality required in this task. Explore the existing code and adapt it for other methods.

3. Implement the following methods as part of the Vector<T> className:

T Max() This method returns the maximum value in a generic sequence. If the source sequence is empty, it returns value which is default for the type T.

T Min() This method returns the minimum value in a generic sequence. If the source sequence is empty, it returns value which is default for the type T.

Vector<T> FindAll(Func<T, bool> searchCriteria) Retrieves all the elements that match the conditions defined by the specified delegate searchCriteria. This method returns an object of the Vector<T> as a newly created vector that contains all the elements that match the conditions, if found; otherwise, an empty Vector<T>. It throws ArgumentNullException when searchCriteria is null.

int RemoveAll(Func<T, bool> filterCriteria) Removes all the elements that match the conditions defined by the specified delegate filterCriteria. This method returns the number of elements removed from the Vector<T>. It throws ArgumentNullException when filterCriteria is null.

In order to implement the Min and Max methods properly, use the Comparer<T> object that you can obtain from the Default property of the Comparer<T> classNameas follows: Comparer<T> comparer = Comparer<T>.Default;

The comparer allows you to call its Compare() method to compare two variables of type T. This is useful when you need to determine whether one variable is greater than another.

4. As you progress with the implementation of the Vector<T> className,you should start using the Tester classNameto extensively test the Vector<T> aiming on the coverage of all potential logical issues and runtime errors. This (testing) part of the task is as important as writing the vector className. The given version of the testing classNamecovers only some basic cases. Therefore, you should extend it with extra cases to make sure that your vector classNameis checked against other potential mistakes.

**Expected Printout **

This section displays the printout produced by the attached Tester className, specifically by its Main method. It is based on our solution. The printout is provided here to help with testing your code for potential logical errors. It demonstrates the correct logic rather than an expected printout in terms of text and alignment.

Test A: Create a new vector by calling 'Vector<int> vector = new Vector<int>(50);'

:: SUCCESS

Test B: Add a sequence of numbers 2, 6, 8, 5, 5, 1, 8, 5, 3, 5

:: SUCCESS

Test C: Run a sequence of operations: Find number that is greater than 3 and less than 7, i.e. 'e => e > 3 && e < 7'

:: SUCCESS

Find number that is either 10 or 8, i.e. 'e => e == 10 || e == 8'

:: SUCCESS

Find number that is not 2, i.e. 'e => e != 2'

:: SUCCESS

Find number that is greater than 20, i.e. 'e => e > 20'

:: SUCCESS

Find the first odd number, i.e. 'e => (e % 2) == 1'

:: SUCCESS

Find the number that is divided by 11 without remainder, i.e. 'e => (e % 11) == 0'

:: SUCCESS

Test D: Find the minimum of the sequence

:: SUCCESS

Test E: Find the maximum of the sequence

:: SUCCESS

Test F: Find all numbers that are greater than 3 and less than 7, i.e. 'e => e > 3 && e < 7'

:: SUCCESS

Test G: Find all numbers that is either 10 or 8, i.e. 'e => e == 10 || e == 8'

:: SUCCESS

Test H: Find all odd numbers, i.e. 'e => (e % 2) == 1'

:: SUCCESS

Test I: Find all odd numbers that are divided by 11 without remainder, i.e. 'e => (e % 11) == 0'

:: SUCCESS

Test J: Remove all even numbers, i.e. 'e => (e % 2) == 0'

:: SUCCESS