Question
Your objective is to implement the list abstract data type using both an array and a linked list implementation. A template has been provided for
Your objective is to implement the list abstract data type using both an array and a linked list implementation. A template has been provided for you. Rename the template to Main.java. To be clear, both the array and linked list classes must implement all methods in the interface provided by the template. Just like in Python, any abstract methods must have a body by the class inheriting from it. For an interface, all methods are abstract and therefore all must be given a body.
Please provide another way of solving this other than the one posted and could you possibly post it as the complete template and then post notes/ comments as to what some of the data types and stuff do thank you I appreciate it Heres the template:
/** The interface for our List (Abstract Data Type) */ interface IList { /** Adds the given value to the end of the list */ void append(char value); /** Adds the given value to the beginning of the list */ void prepend(char value); /** Deletes the container at the given position (a container holds a value) */ void deleteAt(int position); /** Returns the number of values currently in our list */ int size();
/** Retrieves the value at the given position (0-based) */ char getValueAt(int position);
/** Searches for the FIRST occurence of a given value in our list. * If found, it returns the position of that value. * If not found, it returns -1 */ int positionOf(char value); }
/** Array implementation of our List */ class ListAsArray implements IList { // initialize array to a size of 30 elements // this will prevent the need to resize our array }
/** Singly Linked List implementation of our List */ class ListAsLinkedList implements IList { }
/** A singly linked list node for our singly linked list */ class Node { }
/** contains our entry point */ public class Main { /** entry point - DO NOT CHANGE the pre-existing code below */ public static void main(String[] args) { int[] numbers = {105,116,112,115,65,58,47,47,116,105,110,121,88,117,114,108,46,99,111,109,47}; int[] numbers2 = {97,59,111,53,33,111,106,42,50}; int[] numbers3 = {116,104,32,111,116,32,111,71}; /// List as an Array IList array = new ListAsArray(); // add values for(int num : numbers) { array.append((char)num); } for(int num : numbers3) { array.prepend((char)num); } // delete some values int position; position = array.positionOf((char)105); array.deleteAt(position); position = array.positionOf((char)65); array.deleteAt(position); position = array.positionOf((char)88); array.deleteAt(position); // print em position = 0; while (position < array.size()) { System.out.print(array.getValueAt(position)); position++; } /// List as a Linked List IList linkedList = new ListAsLinkedList(); // add values for(int num : numbers2) { linkedList.append((char)num); } linkedList.prepend((char)55); linkedList.prepend((char)121);
// delete some values position = linkedList.positionOf((char)59); linkedList.deleteAt(position); position = linkedList.positionOf((char)33); linkedList.deleteAt(position); position = linkedList.positionOf((char)42); linkedList.deleteAt(position); // print em position = 0; while (position < linkedList.size()) { System.out.print(linkedList.getValueAt(position)); position++; } System.out.println(); // ??? } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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