20 terms

Collections Review

STUDY
PLAY
What do arrays contain?
A group of values of the same data type
What method would you call to remove all of the nodes from a linked list?
Clear()
All array variables are of what data type, regardless of what the array contains?
reference
Write an expression that shows how to access the 4th element in an array called "myData".
myData[3]
How would you best visualize a one-dimensional and two-dimensional array?
A one-dimensional array is line and a two-dimensional array is grid of elements.
How can you determine the number of elements in a one-dimensional array?
Read the Length property or call GetLength(0)
What is a linked list?
A data structure that holds a series of elements called nodes
What is the difference between a singly-linked list and a doubly-linked list?
Each element in a singly-linked list only knows how to reach the next element. Doubly-linked list elements know how to reach previous and next elements.
What is an advantage of using a linked list over an array?
Linked lists can grow or shrink without reallocating all elements & you can more easily add or remove elements from the middle of the list
Given the following array:
int[ ] myArray = new int[4] { 5, 10, 15, 20 };

What is the result of the following code:
int num = 0;
for (int i = 0; i < myArray.Length; i++)
{
num += myArray[i];
}
MessageBox.Show(num.ToString());
A MessageBox with the value 50
Given the following array:
int[ ] myArray = new int[5];

Consider the following code:
for (int i = 0; i < myArray.Length; i++)
{
myArray[i] = i * 5;
}
What values are now in the array?
The values: 0, 5, 10, 15, 20
Given the following array:
String[ ] myArray = new String[4] {"cat", "dog", "fish", "horse"};

What is the result of the following code:
int index;
for (index = 0; index < myArray.Length; index++)
{
if (myArray[index].Equals("fish"))
break;
}
MessageBox.Show(index.ToString());
A MessageBox with the value 2
Which of the following statements declares a variable called "myInts" that can hold a linked list of int values?
LinkedList<int> myInts= new LinkedList<int>();
Which of the following code statements would remove the value "3" from a linked list named myList?
myList.Remove("3");
Which of the following statements declares a variable called "myStrings" that can hold a linked list of strings?
System.Collections.Generic.LinkedList<string> myStrings;
Arrays and Linked Lists are both examples of ___________.
collections
T/F
The foreach command works the same for both a Linked List and an array.
true
The .NET Framework defines a number of very useful collections and related objects in the which namespace?
The System.Collections namespace
What is the result of the following code:

int[ ] myArray = new int[3] { 5, 10, 15 };
int sum = 1;
foreach (int value in myArray)
{
sum *= value;
}
MessageBox.Show(sum.ToString());
A MessageBox with the value 750
Given the following array:

int[ ] myArray = new int[3] { 5, 10, 15 };

How would you get an enumerator to navigate the array?
System.Collections.IEnumerator iterator = myArray.GetEnumerator();
YOU MIGHT ALSO LIKE...