Reference no: EM131219929
As we have discussed in class, section 4.1 of our text develops a List ADT and then offers two different implementations of it in the classes AList and LList.
The ADT is defined in a Java interface file List.java, and both AList and LList implement all the required methods of this interface. As a result, either implementation can be used, and while their internal methods and means of storing data differ, both give identical behavior.
During a recent class meeting, we wrote a class that created either an AList or LList object, used a few methods such as insert and remove, and printed it out. We saw that these features all worked correctly for both AList and LList objects; our code simply called the methods defined in the List interface and they worked.
For this assignment, you will write a new class and create three methods that take one (or two) List objects and perform operations on them using only the public List methods. Here are the three methods to write:
1 Write a method static void swap (List<Integer> l) which interchanges the current element in the list and the one following it. (First make it work in the normal case; then, if you still have time, make sure it handles special cases, such as: the list is empty; the list has only one element; current is at the end of the list
2 Write a method static void reverse (List<Integer> l) which reverses the order of items stored in the list. Again, make sure it works for any special cases you can think of.
3 Write a method static List mergeLists (List<Integer> l1, List<Integer> l2) which takes two sorted Lists as input, producing a new List containing all the elements of both lists, also sorted. The new list is the return value for the method.
In your test class's main method, write a series of statements to create several AList and/or LList objects (of type <Integer>) and put some data into them by calling the List append and/or insert methods. Use the lists you build as parameters to test each of your three methods and show that they work.
Test each of your three methods with a minimum of three different test inputs. Show that your methods work for various test cases such as the examples given above. Make sure your program prints the 'before' and 'after' lists for each of your tests.
Finally, copy the output of your program to a '.txt' or '.doc' file. Don't forget to put your name at the top of the document.
Attachment:- Assignment.rar
How do nations differ in hrm
: How do nations differ in HRM? What are the major national context characteristics that affect IHRM?
|
Identify the major business and financial risks
: Identify the major business and financial risks such as interest rate risk, foreign exchange risk, credit, commodity, and operational risks. How do organizations measures risk and what global initiatives exist in financial risk management?
|
What data integrity and security issues do you foresee
: The combined practice wants to implement wireless notepads for the physicians and staff to make changes directly to a patient's records. What data integrity and security issues do you foresee?
|
How much was new company net income or net loss
: Assume that new Towne Company reported the following summarized data at September 30, 2016. Accounts appear in no particular order; dollar amounts are in millions. Prepare the trial balance of New Towne at September 30, 2016. List the accounts in th..
|
Write a method which reverses the order of items
: Write a method static void reverse (List l) which reverses the order of items stored in the list. Again, make sure it works for any special cases you can think of - write a series of statements to create several AList and/or LList objects (of typ..
|
Function of a particular set of circumstances
: Almost all business situations are both complex a unique and are a function of a particular set of circumstances and individuals in which multiple realities exist that cannot be reduced to the sum of its parts (Saunders, Lewis and Thornhill 2012)...
|
Accounts payable-service revenue-cash-cost of goods sold
: The Marchetti Soup Company entered into the following transactions during the month of June: (1) purchased inventory on account for $180,000 (assume Marchetti uses a perpetual inventory system); T-accounts: Accounts recievable, Accounts payable, Serv..
|
Complete slide presentation for the board of directors
: Prepare a complete slide presentation for the Board of Directors (BOD) outlining the justification for implementing an improved Accounting and Control (AC) function describing activities, applications, justification and benefits of implementing an..
|
Are there conflicts of interest in the given deal
: Are there conflicts of interest in this deal? If yes, will they help or hurt the deal? Are there real potential synergies in this merger? Will this deal create value for the shareholders of Tesla?Is the deal rightly priced?
|