Question
You will be submitting two solutions: a non-generic solution implemented using procedural programming and a Generic solution implemented using generic programming principles learned in class.
You will be submitting two solutions: a non-generic solution implemented using procedural programming and a Generic solution implemented using generic programming principles learned in class.
Get started:
Open your eclipse IDE and do the following tasks:
PART 1. Create a Java Project named Lab4_Fname_Lname. Add to your project, the starter code provided, namely the files:
- DoublyLinked.java
- TestDLLApp.java
- Include declaration shown above with your First Name and Last Name to both source files (i) and (ii)
PART 2. Create the following methods in DoublyLinkedList class
- A method called deleteFirstNode() to delete first node [assumes a non-empty list]
- A method called deleteLastNode() to delete last node [assumes a non-empty list]
- A method called searchAndDelete (int number) that searches for, deletes and returns the node containing the int provided as parameter
- A method called printForwards() to print out the data in the linkedlist from first to last
- A method called printBackwards() to print out the data in the linkedlist from last to first
PART 3. Add code to the main() method in TestDLLApp class to do the following:
make a new linked list called newLL
insert 20, 42, 63, 93 at the front of linked list: Hint=> call relevant method
insert 9, 34, 51 at the rear of linked list: Hint=> call relevant method
display data elements in the linked list from first to last: Hint=> call printForwards() created in PART 2.
display data elements in the linked list from last to first:Hint=> call printBackwards() created in PART 2.
delete first item Hint: call relevant method
delete last item
delete item with number 9: Hint=> call searchAndDelete(9) created in PART 2
display data elements in the linked list from first to last:Hint: call printForwards() created in PART 2.
insert 69 after 20
insert 77 after 34
display data elements in the linked list from first to last
Part 4: Using Generic linkedlist: Create a copy of your program and use it to create a generic linklist application and test it with the all the insert, display and delete methods above. In other words, you are to create a GENERIC SOLUTION - by applying generic programming taught in class.
Part 5: Create a comprehensive Javadoc for your application.
EXPECTED OUTPUTfrom the Linked List App when run is:
Linked List: [From first_to_last]: 93 63 42 20 9 34 51
Linked List: [From last_to_first]: 51 34 9 20 42 63 93
Linked List: [From first_to_last]: 63 42 20 34
Linked List: [From first_to_last]: 63 42 20 69 34 77
Test plan is not required.
Rubric
Non-generic /Procedural Version of the Application 2 source files each with declaration bearing student names | marks |
deleteFirstNode() method | 1 marks |
deleteLastNode() method | 1 marks |
searchAndDelete() method | 1 marks |
printForwards() method | 1 marks |
printBackwards() method | 1 marks |
TestDLLApp: correct method invocations + correct output + Javadoc | 1 marks |
Generic version of the application submitted - with 2 source files: i.e. Created and submitted a GENERIC SOLUTION by applying generic programming taught in class. | 4 marks |
Total | 10 marks |
DoublyLinked.java :
// ===================== class starts here============================= class Node { public int mData; // data item public Node next; // next node in list public Node previous; // previous node in list // ------------------------------------------------------------- public Node(int d) // constructor { mData = d; } // ------------------------------------------------------------- // display this node data public void displayNode() { System.out.print(mData + " "); } // ------------------------------------------------------------- } // end class Node // ===================== class design starts here ============================= class DoublyLinkedList { private Node first; private Node last; // ------------------------------------------------------------- public DoublyLinkedList() { first = null; last = null; } // ------------------------------------------------------------- public boolean isEmpty() { return first == null; } // ------------------------------------------------------------- public void insertFirst(int num) { Node newNode = new Node(num); // write your code here } // ------------------------------------------------------------- public void insertLast(int num) { // write your code here } // insert newNumber just after numToFind public boolean insertAfter(int numToFind, int newNumber) { // (assumes non-empty list) // write your code here } // ------------------------------------------------// delete first node public Node deleteFirstNode() { // write your code here } // -----------------------------------------------// delete last node public Node deleteLastNode() { // write your code here } // ------------------------------------------------------------- // -----------------------------------------finds, deletes and returns the node // that contains the given int value public Node searchAndDelete(int number) { // write your code here } // -------------------------------------------display data from first node to // last node public void printForwards() { // write your code here } // -------------------------------------------display data from last node to // first node public void printBackwards() { // write your code here } // ------------------------------------------------------------- } // end class DoublyLinkedList // ==========================================================
TestDLLApp.java :
class TestDLLApp { public static void main(String[] args) { // write your lines of code here } // end of main() method } // end class TestDLLApp
Step by Step Solution
There are 3 Steps involved in it
Step: 1
DoublyLinked class starts here class Node public int mData data item public Node next next node in list public Node previous previous node in list public Nodeint d constructor mData d display this nod...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started