Menu

Program 3 List Abstract Data Type Description Objective Implement List Abstract Data Type Q43795340

Program #3 The List Abstract Data Type Description: Yourobjective is to implement the list abstract data type using both anarray and a linked list implementation. A template has beenprovided for you. Rename the template file to “Main.java”. To beclear, both the array and linked list classes must implement allmethods in the interface provided by the template. Just like inPython, any abstract methods must have a body by the classinheriting from it. For an interface, all methods are abstract andtherefore all must be given a body. Some of the implementation hasbeen done for you. You are required to use the given template andare not allowed to change the existing code provided. Read allJavaDoc comments in the template for further instruction and besure to follow those comments in your implementation. No exampleoutput will be given for this assignment (there is a good reasonfor this). You will know when you are receiving correct output fromyour code. About JavaDocs: For this assignment, it is not necessaryto provide JavaDoc comments on your methods. This is because theJavaDoc comments have already been given in the interface and yourmethods should follow those comments. The classes are alreadycommented for you as well. Any fields you create, however, shouldhave JavaDoc comments. Recommendation for this assignment: Irecommend “stubbing” the methods at first. Remember from Livingwith Cyber that a method stub is a placeholder, where you simply donothing in the body. This will help you focus on getting one methodto work at a time. Some methods require a value to be returned.When stubbing these simply return any hard coded value that matchesthe datatype. You can change it later when you actually implementthe method. Finally, I would strongly recommend you write your ownentry point and rename mine (to “main2” or something like that).This will allow you to test each function out one at a time. Onlyrun my entry point once you are sure everything is working. Whenthe program fully works, get rid of your test main function andsubmit 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 holdsa 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 ourlist.
* 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();
  
// ???
} }

Expert Answer


Answer to Program #3 The List Abstract Data Type Description: Your objective is to implement the list abstract data type using bot…

OR