Need help with this:
Given the following challenges, use append(), extend(), pop(), and insert()to change the contents of the lists.
Suppose that we have the following list:
Strawberry, Blueberry, Blackberry, Cranberry
Define the list berries with the following elements shown in Snippet 5.11:
Strawberry, Blueberry, Blackberry, Cranberry
-
Using the built-in append() method, add the value Raspberry to the list berries.
-
Using the built-in extend() method, extend an empty fruits list from the berries list that you created previously.
-
Insert Mangoes into the fruits list at index 2 using the built-in method insert().
-
Remove the element at index 1 from the fruits list using the built-in method pop() and replace it with Apples, using the insert() built-in method.
-
Finally, sort the elements in the fruits list by using the built-in method sort() with keyword arguments. Set the key argument to None and the reverse argument to False.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 1 images
- Implement the following method using the Fork/JoinFramework to assign random values to the list.public static void parallelAssignValues(double[] list)Write a test program that creates a list with 9,000,000 elements and invokesparallelAssignValuesto assign random values to the list. Also implement asequential algorithm and compare the execution time of the two. Note if you useMath.random(), your parallel code execution time will be worse than the sequentialcode execution time because Math.random() is synchronized and cannot beexecuted in parallel. To fix this problem, create a Random object for assigningrandom values to a small list.arrow_forwardYou are going to implement a program that creates an unsorted list by using a linked list implemented by yourself. NOT allowed to use LinkedList class or any other classes that offers list functions. It is REQUIRED to use an ItemType class and a NodeType struct to solve this homework. The “data.txt” file has three lines of data 100, 110, 120, 130, 140, 150, 160 100, 130, 160 1@0, 2@3, 3@END You need to 1. create an empty unsorted list 2. add the numbers from the first line to list using putItem() function. Then print all the current keys to command line in one line using printAll(). 3. delete the numbers given by the second line in the list by using deleteItem() function. Then print all the current keys to command line in one line using printAll().. 4. putItem () the numbers in the third line of the data file to the corresponding location in the list. For example, 1@0 means adding number 1 at position 0 of the list. Then print all the current keys to command line in one…arrow_forwardThe implementations of the methods addAll, removeAll, retainAll, retainAll, containsAll(), and toArray(T[]) are omitted in the MyList interface. Implement these methods. Use the template at https://liveexample.pearsoncmg.com/test/Exercise24_01_13e.txt to implement these methods this the code i have for the write your own code part import java.util.Iterator; interface MyList<E> extends java.util.Collection<E> { void add(int index, E e); boolean contains(Object e); E get(int index); int indexOf(Object e); int lastIndexOf(E e); E remove(int index); E set(int index, E e); void clear(); boolean isEmpty(); Iterator<E> iterator(); boolean containsAll(java.util.Collection<?> c); boolean addAll(java.util.Collection<? extends E> c); boolean removeAll(java.util.Collection<?> c); boolean retainAll(java.util.Collection<?> c); Object[] toArray(); <T> T[] toArray(T[] a); int size();} and its…arrow_forward
- Hi, I am not sure what's wrong with my code. Can you please check why it is giving me an error? In the starter file is a partial implementation of a doubly-linked list in DoublyLinkedList.java. We will write three new methods in this class to provide additional functionality. Write a method addFirst that adds a new element at the beginning of a DoublyLinkedList. Write a method addLast that adds a new element at the end of a DoublyLinkedList. Write a method removeFirst that removes and returns the first element of a DoublyLinkedList. Try to keep your implementations as simple as possible. For example, recall this definition of addFirst in the (Singly) LinkedList class: public void addFirst(E value) { head = new Node(value, head); } In the DoublyLinkedList class, you will need to keep the three instance variables head, tail, and count updated in all methods. Note that addFirst and addLast will be symmetric to each other, as will removeFirst and removeLast (provided in the…arrow_forwardCreate a nested class called DoubleNode that allows you to create doubly-linked lists with each node containing a reference to the item before it and the item after it (or null if neither of those items exist). Then implement static methods for the following operations: insert before a given node, insert after a given node, remove a given node, remove from a given node, insert at the beginning, insert at the end, remove from a given node, and remove a given node.arrow_forwardGiven the MileageTrackerNode class, complete main() in the MileageTrackerLinkedList class to insert nodes into a linked list (using the insertAfter() method). The first user-input value is the number of nodes in the linked list. Use the printNodeData() method to print the entire linked list. DO NOT print the dummy head node. Ex. If the input is: 3 2.2 7/2/18 3.2 7/7/18 4.5 7/16/18 the output is: 2.2, 7/2/18 3.2, 7/7/18 4.5, 7/16/18 public class MileageTrackerNode { private double miles; // Node data private String date; // Node data private MileageTrackerNode nextNodeRef; // Reference to the next node public MileageTrackerNode() { miles = 0.0; date = ""; nextNodeRef = null; } // Constructor public MileageTrackerNode(double milesInit, String dateInit) { this.miles =…arrow_forward
- A consecutive sequence a list of numbers that are organized in increasing order with the next eleme. one bigger than the current. Write a non-recursive method "lengthConsec", which takes an IntNode myList as the parameter and returns the length of the consecutive sequence in myList. To simplify the implementation, you can assume that there is no more than one consecutive sequence in the list. For example, in the following linked list, the consecutive sequence begins at node "5" and ends at node "7", so lengthConsec (myList) should return 3 in this case. myList 8 13 4 public class IntNode { 12 private int m_data; private IntNode m_link; Consecutive sequence 6 7 28arrow_forwardJump to level 1 A list of fruits is searched for Pear using binary search. Fruits list: [Apple, Apricot, Berry, Grape, Lemon, Lime, Orange, Peach, Pear, Plum] What is the first fruit searched? Pick ↑ What is the second fruit searched? Pick 1 Check ✪ Next 2 3 4 5arrow_forwardI'm trying to understand LargeIntList classes for lists, I was wondering these statements or True or False? either or, can you please explain your answers? Thank you. Uses the “by copy” approach with its elements. Implements the ListInterface interface. Keeps its data elements sorted. Allows duplicate elements. Uses the LLNode class of the support package. Throws an exception if an iteration “walks off ” the end of the list. Throws an exception if an element is added when it is "full". Supports addition of elements at the front of the list, the end of the list, and anywhere in between. Can hold objects of any Java class. Has only O(1) operations, including its constructor. Provides more than one Iterator.arrow_forward
- Without using the java collections interface (i.e. do not import java.util.List, LinkedList, etc. ) Write a java program that inserts a new String element (String newItem) into a linked list before another specified item (String itemToInsertBefore). For example if items "A", "B", "C" and "D" are in a linked list in that order and the below method is called, insertBefore("E", "C"), then "E" would be inserted before "C", making the final list to be "A", "B", "E", "C" and "D" with no nulls or blank elements or any elements missing or anything. It should work for all lenghths of linkedlists of Strings. public Boolean insertBefore(String newItem, String itemToInsertBefore) { // returns true if done successfully, else returns false if itemToInsertBefore cannot be found or some other error }arrow_forwardI'm trying to understand LargeIntList classes for lists, I was wondering these statements or True or False? either or, can you please explain your answers? If you need more info, I can provide an image of the textbook I am refering LargeIntList to, it is chapter 6, section 6. Thank you. Supports addition of elements at the front of the list, the end of the list, and anywhere in between. Can hold objects of any Java class. Has only O(1) operations, including its constructor. Provides more than one Iterator.arrow_forwardTwo sorted lists have been created, one implemented using a linked list (LinkedListLibrary linkedListLibrary) and the other implemented using the built-in ArrayList class (ArrayListLibrary arrayListLibrary). Each list contains 100 books (title, ISBN number, author), sorted in ascending order by ISBN number. Complete main() by inserting a new book into each list using the respective LinkedListLibrary and ArrayListLibrary insertSorted() methods and outputting the number of operations the computer must perform to insert the new book. Each insertSorted() returns the number of operations the computer performs. Ex: If the input is: The Catcher in the Rye 9787543321724 J.D. Salinger the output is: Number of linked list operations: 1 Number of ArrayList operations: 1 import java.util.Scanner;import java.io.FileInputStream;import java.io.IOException; public class Library { public static void fillLibraries(LinkedListLibrary linkedListLibrary, ArrayListLibrary arrayListLibrary) throws…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education