Assignment 4
CS141 – Computer Programming II
Chapter 15 – Intro. to Data Structure
Assignment 4 worth 5 points (50/10). Due on Saturday 10/12/2016. Will
deduct 1 point for each day late. Copying each other work will result in
giving 0 to both.
The first Question Q1. Will require you to submit your program as .java file
that can be run.
The rest of the questions can be answerd as word document file. Please
use the following way to name your file:
Your answer file name as: StudentId_CS141_Assignment04, where StudentId is
your student id
Q1. Write the java code to create a linked list of string type. Then, apply the
following operations using the library and the available functions:
[10 points]
1. Add the following node in the same order: “Ali”, “Sara”, “Omar”,
“Eman”
2. Add at the beginning the node “Ahmad”
3. Print the whole list
4. Add the node “Heba” between node “Ali” and node “Sara” using
iterator
5. Remove the last node
6. Re-print the whole list
Here is the expected output of the program
OUTPUT
Q2. In the ListIterator class, what is the difference between next() and
hasNext() methods?
[5 points]
Q3. (a) What does the Linked List library Iterator method set() do? (b)
And write just one line of java code just to call the set method given the
following: [5 points]
We have a linked list of Student class called students each node in this
linked list is an object of type Student. And List Iterator called stdIter
pointing to the first node as given by the following code:
LinkedList <Student> students = new LinkedList <Student>
();
ListIterator <Student> stdIter = students.listIterator();
stdIter.next(); // move the
iterator once
Student std1 = new Student(); // construct a new
Student object called std1
Now write the one line code to call the set()method on the iterator
passing it the new object.:
Q4. Part(a) show the output for the following code the uses a Queue:
[5 points]
Get Free Quote!
432 Experts Online