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

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...
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.
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...
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...
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...
use java for : 1. Write a method called indexOfMax that takes an array of integers...
use java for : 1. Write a method called indexOfMax that takes an array of integers and returns the index of the largest element. 2. The Sieve of Eratosthenes is “a simple, ancient algorithm for finding all prime numbers up to any given limit” (https://en.wikipedia. org/wiki/Sieve_of_Eratosthenes).Write a method called sieve that takes an integer parameter, n, and returns a boolean array that indicates, for each number from 0 to n -1, whether the number is prime.
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.
Array-Based Linked List Implementation: JAVA Decide how to write the methods with items being stored in...
Array-Based Linked List Implementation: JAVA Decide how to write the methods with items being stored in an array. NOT in linked List. Implement an array-based Linked List in your language. Use double as the item. You need to create a driver includes several items and inserts them in order in a list. Identify the necessary methods in a List Linked implementation. Look at previous Data Structures (stack or queue) and be sure to include all necessary methods. DO NOT USE...
In Java: Write a method called copy, which is passed A[], which is an array of...
In Java: Write a method called copy, which is passed A[], which is an array of int, and an integer n. The method returns a new array consisting of the first n items in A[]. Write a method called slice, which is passed A[], which is an array of int, an integer i and an integer j. The method returns a new array consisting of all of the items in A from A[i] to A[j] inclusive.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT