This needs to be done in Visual Studios. Define a class called ArrayList. It wil
ID: 653892 • Letter: T
Question
This needs to be done in Visual Studios.
Define a class called ArrayList. It will be templated.
The instance variable in the ArrayList will be a LinkedList containing the type.
You will implement the following functions on ArrayList.
int size(); // Determine how many elements are in the list.
int get(int index); // Retrieve the element at the location indicated by the parameter.
void set(int index,T t); // Set the element at the location indicated by the parameter.
bool contains(T t); // Determines if the list contains the paramter.
void add(T t); // Add an element to the end of the list.
bool remove(T t); // Remove all occurrences of an element from the list.
void addAll(ArrayList<T> list); // Add all elements from a list
void sort(); // Sort the elements in the list in ascending order using Selection Sort
void sort(bool); // Sort the elements in the list in descending order using Bubble Sort
T* toArray(int& size); // Convert the ArrayList to an array
The instance variable in the ArrayList will be a LinkedList. Each node in the LinkedList will contain an int which is the index and an elements of the type in the list.
After you have written the ArrayList, use it to write a function that will read from a file and print out the unique words found in the file in ascending order.
Explanation / Answer
Dim FStrm As FileStream
Dim StrmR As StreamReader
FStrm = New FileStream("HighScores.txt", FileMode.Open)
StrmR = New StreamReader(FStrm)
Dim highScores As New List(Of String)
While StrmR.Peek <> -1
highScores.Add(StrmR.ReadLine)
End While
FStrm.Close()
Console.WriteLine(" __________________________________________________________________ ")
Console.WriteLine(" | Score | Name |")
Console.WriteLine(" |-------------------|----------------------------------------------|")
Dim Scores() As String
For Each score As String In highScores
Scores = score.Split(",")
Console.WriteLine(" | {0} | {1} |", Pad(Scores(0), 15), Pad(Scores(1), 40))
Next
Console.WriteLine(" |___________________|______________________________________________| ")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.