Consider the attached TestBag program, which uses the ArrayBag class.
What will this print?
Add code to this program so that it does the following:
Creates a new bag, bag3, that contains everything in bag1 and bag2 combined.
Reads in a string from the user and checks to see if that string is in
bag3; prints an appropriate message.
Removes a random item from bag3 and adds that item to bag1.
Creates a new, empty bag (bag4).
Adds everything in bag1 to bag4.
Checks to see if bag1 and bag4 contain the same elements; prints
an appropriate message.
Repeatedly removes and prints random items from bag4 until it is empty.
Consider the LinearNode class that we discussed in class.
Assume that variable front is of type
LinearNode, and that it points to a list containing at least one node.
What does the following code do?
LinearNode newNode = new LinearNode("whatever");
LinearNode temp = front;
while (temp.getNext() != null)
temp = temp.getNext();
temp.setNext(newNode);
What would the code above do if the list were empty? Explain.
Write code to print each element in the list.
Write code that creates a new node and makes it be the second node
in the list.