Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program #3 The List Abstract Data Type Description: Your objective is to implement the list abstract data type using both an array and a linked

Program #3 The List Abstract Data Type Description: 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 file 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. Some of the implementation has been done for you. You are required to use the given template and are not allowed to change the existing code provided. Read all JavaDoc comments in the template for further instruction and be sure to follow those comments in your implementation. No example output will be given for this assignment (there is a good reason for this). You will know when you are receiving correct output from your code. About JavaDocs: For this assignment, it is not necessary to provide JavaDoc comments on your methods. This is because the JavaDoc comments have already been given in the interface and your methods should follow those comments. The classes are already commented for you as well. Any fields you create, however, should have JavaDoc comments. Recommendation for this assignment: I recommend stubbing the methods at first. Remember from Living with Cyber that a method stub is a placeholder, where you simply do nothing in the body. This will help you focus on getting one method to work at a time. Some methods require a value to be returned. When stubbing these simply return any hard coded value that matches the datatype. You can change it later when you actually implement the method. Finally, I would strongly recommend you write your own entry point and rename mine (to main2 or something like that). This will allow you to test each function out one at a time. Only run my entry point once you are sure everything is working. When the program fully works, get rid of your test main function and submit the program. Submitting your assignment: Submit only your Main.java file on Moodle. Do not submit any .class files

/** 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 */ 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

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_2

Step: 3

blur-text-image_3

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

Students also viewed these Databases questions

Question

1. What are your creative strengths?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago