Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The linked list is at the core of most data structures. We see it in lists, stacks, queues and trees to name a few. From

The linked list is at the core of most data structures. We see it in lists, stacks, queues and trees to name a few.

From the lecture material create a linked list class. This class should be generic so that it will operate on any given type. In C++ we call this a template class. In Java it is a Generic. Of course in Java a generic will not operate on a primitive type but that should be ok for what we are doing

Your class should have the following functionality:

  • void addToEnd(T data) - adds an item to the end of the list
  • void insert(T search, T data) - Adds data as a new Node following the node that contains search
  • deleteNode(T search) - Deletes the node that contains search.
  • void printList() - Prints the entire linked list.
  • bool contains(T search) - returns true if the list contains T and false if it doesn't

If you find there is other functionality that you feel is needed to make your list better then by all means feel free to add it.

Using the PairList class you created in project 2 remove the vector and replace it with the LinkedList you created in Task 1 above. This means that your PairList should now be derived from LinkedList and not vector.

import java.util.ArrayList;

public class PairList extends ArrayList { void addPair(T first, T second) { add(new Pair(first,second)); } T getFirst(T second) { for(Pair P : this) { if(P.getSecond().equals(second)) { return (T)P.getFirst(); } } return null; } T getSecond(T first) { for(Pair P : this) { if(P.getFirst().equals(first)) { return (T)P.getSecond(); } } return null; } void deletePair(T first, T second) { for(int x=0; x();> { Pair P = get(x); if(P.getFirst().equals(first) && P.getSecond().equals(second)) { remove(P); } } } void printList() { int count = 0; for(Pair P : this) { System.out.println( " Index [" + count + "]: " + P); count+=1; } } }

JAVA ONLY

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

Business Statistics

Authors: Norean Sharpe, Richard Veaux, Paul Velleman

3rd Edition

978-0321944726, 321925831, 9780321944696, 321944720, 321944690, 978-0321925831

More Books

Students also viewed these Programming questions

Question

Describe the basic hypothesis testing procedure.

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

In a system with light damping (c Answered: 1 week ago

Answered: 1 week ago