Question

In: Computer Science

Please write in JAVA 1. Given the following array-based ADT list called colorList whose elements contain...

Please write in JAVA

1. Given the following array-based ADT list called colorList whose elements contain strings
            red, orange, yellow, blue, indigo, violet
write the statement to insert the String element “pink” to the end of the list. Assume the front of the list is on the left.

2. Outline the basic steps to remove a node from the beginning of a list.

Completed answers will be given an immediate upvote :)

Solutions

Expert Solution

Code using inbuilt arraylist (just copy and paste to see the output)

import java.util.*;//util class contains arraylist
public class HelloWorld{

     public static void main(String []args){
        ArrayList<String> colourlist=new ArrayList<String>();//creating a arraylist of type string with name as colourlist
        colourlist.add("red");
        colourlist.add("orange");
        colourlist.add("yellow");
        colourlist.add("blue");
        colourlist.add("indigo");
        colourlist.add("violet");
        System.out.println("creating the colourlist with predfined and now outputing each element");
        for(int i=0;i<colourlist.size();i++){
            System.out.println(colourlist.get(i));
        }
        //actual code given from here
        //adding pink to end of list
        colourlist.add("pink");//add basically adds element to end of arraylist adt
        System.out.println("displaying the colourlist adding the element pink to end of list");
        for(int i=0;i<colourlist.size();i++){
            System.out.println(colourlist.get(i));
        }
        //NOW I AM REMOVING THE FIRST ELEMENT FROM LIST
        colourlist.remove(0);//remove o means remioving first element from list
        System.out.println("colourlist after removing the first element ie red");
        for(int i=0;i<colourlist.size();i++){
            System.out.println(colourlist.get(i));
        }
        System.outprintln("in arraylist elements are deleted and inserted as deleted or inserted in simple array this process is carried by compiler itself");
     }
}//end of class


Related Solutions

Write an array-based implementation of the ADT list that expands the size of the array of...
Write an array-based implementation of the ADT list that expands the size of the array of list entries as needed so that the list can always accommodate a new entry. Also reduce the size of the array as needed to accommodate several removals. When the size of the array is greater than 20 and the number of entries in the list is less than half the size of the array, reduce the size of the array so that it is...
Java The List ADT has an interface and a linked list implementation whose source code is...
Java The List ADT has an interface and a linked list implementation whose source code is given at the bottom of this programming lab description. You are to modify the List ADT's source code by adding the method corresponding to the following UML: +hasRepeats() : boolean hasRepeats() returns true if the list has a value that occurs more than once in the list hasRepeats() returns false if no value in the list occurs more than once in the list For...
Java The List ADT has an interface and a linked list implementation whose source code is...
Java The List ADT has an interface and a linked list implementation whose source code is given at the bottom of this programming lab description. You are to modify the List ADT's source code by adding the method corresponding to the following UML: +hasRepeats() : boolean hasRepeats() returns true if the list has a value that occurs more than once in the list hasRepeats() returns false if no value in the list occurs more than once in the list For...
JAVA: Implement a Queue ADT using a circular array with 5 string elements. Create a Queue...
JAVA: Implement a Queue ADT using a circular array with 5 string elements. Create a Queue object and try various operations below. Queue myQueue = new Queue(); myQueue.enqueue(“CPS 123”); myQueue.enqueue(“CPS 223”); myQueue.enqueue(“CPS 323”); myQueue.dequeue(); myQueue.enqueue(“CPS 113”); myQueue.enqueue(“CPS 153”); string course = myQueue.front(); // course should be CPS 223 size = myQueue.size(); // size should be 4 // output course and size
Using the implementation of the array based list given, write a CLIENT method (that is NOT...
Using the implementation of the array based list given, write a CLIENT method (that is NOT part of the class) called replace, that given a value and a position replaces the value of the element at that position. REMEMBER error checking public static void replace( List aList, int newValue, int position) public class ArraybasedList implements MyListInterface{ private static final int DEFAULTSIZE = 25; // Data members: private int currentSize; private int maxSize; private S[] elements; //default constructor has NO parameters...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector...
In C++ write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items.
Part 1:Write a program in Java that declares an array of 5 elements and displays the...
Part 1:Write a program in Java that declares an array of 5 elements and displays the contents of the array. Your program should attempt to access the 6th element in the array (which does not exist) and using try. catch your program should prevent the run-time error and display your error message to the user. The sample output including the error message is provided below. Part (1) Printing an element out of bounds 5 7 11 3 0 You went...
Recursion java: 1. Write a recursive algorithm to add all the elements of an array of...
Recursion java: 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C .4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
Develop and test two Java classes: an array-based stack ADT that implements the provided StackInterface.java a...
Develop and test two Java classes: an array-based stack ADT that implements the provided StackInterface.java a linked list-based queue ADT that implements the provided QueueInterface.java You may not make any changes to StackInterface.java or QueueInterface.java The classes must be generic The attached generic singly linked list node class, LLNode.java, must be used for the queue implementation; you may not make any modifications to this class Your implementations cannot throw any exceptions Each ADT must include a toString( ) method: The...
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class...
Question: Write an implementation of the ADT sorted list that uses a resizable array (vector class of C++ STL) to represent the list items. Anytime the list becomes full, double the size of the array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT