Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LINKEDLIST3: public class LinkedList3 { private class Node { private T data; private Node link; //reference public Node() { data = null; link = null;

LINKEDLIST3: public class LinkedList3 { private class Node { private T data; private Node link; //reference public Node() { data = null; link = null; } public Node (T newData, Node linkValue) { data = newData; link = linkValue; } } private Node head; public LinkedList3() { head = null; } public void addToStart(T itemData) { head = new Node(itemData,head); } public boolean deleteHeadNode() { if(head != null) { head = head.link; return true; } else return false; } public int size() { int count = 0; Node position = head; while(position != null) { count++; position = position.link; } return count; } public boolean contains(T item) { return (find(item) != null); } private Node find(T target) { Node position = head; T itemAtPosition; while(position != null) { itemAtPosition = position.data; if(itemAtPosition.equals(target)) return position; position = position.link; } return null; } public void outputList() { Node position = head; while(position != null) { System.out.println(position.data); position = position.link; } } public boolean isEmpty() { return (head == null); } public void clear() { head = null; }

public boolean equals(Object otherObject) { if(otherObject == null) return false; else if(getClass() != otherObject.getClass()) return false; else { LinkedList3 otherList = (LinkedList3)otherObject; if (size()!= otherList.size()) return false; Node position = head; Node otherPosition = otherList.head; while(position != null) { if(!(position.data.equals(otherPosition.data))) return false; position = position.link; otherPosition = otherPosition.link; } return true; } } }

EXAMPLE OF GENERICLinkedlistdemo: public class GenericLinkedListDemo { public static void main(String[] args) { // TODO Auto-generated method stub LinkedList3 list = new LinkedList3(); Entry entry1 = new Entry("Apples",1); list.addToStart(entry1); Entry entry2 = new Entry("Bananas",2); list.addToStart(entry2); Entry entry3 = new Entry("Cantaloupe",3); list.addToStart(entry3); System.out.println("List has " + list.size() + " nodes."); list.outputList(); System.out.println("End of list."); } }

(1) Please create a generic linked list with node.You can use LinkedList3 for this project. 2) Please create a Student class by yourself: (a) private instance variables: String first name, String last name, String student ID, Birthday (date, month, year) ( this could be a class: Date) (b) constructor with parameters (c) toString() function to return the data (3) Please create a driver class: a. Create an empty linked list first with Student type. b. Create 4 student objects with name, student ID and birthrate. c. Add each student to the linked list by calling the method: addToStart() d. Print the whole list by calling the method: outputList() e. Print the size of the list by calling the method: size()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

Students also viewed these Databases questions