Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; import java.util.LinkedList; public class Main{ final static int TIMES = 50000; public static void addLastArrayList(){ long startTime = System.nanoTime(); ArrayList list = new

import java.util.ArrayList; import java.util.LinkedList; public class Main{ final static int TIMES = 50000; public static void addLastArrayList(){ long startTime = System.nanoTime(); ArrayList list = new ArrayList(); for (int i = 0; i < TIMES; i++) // TODO append the value of the index variable i to the end of the ArrayList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void addFirstArrayList(){ long startTime = System.nanoTime(); ArrayList list = new ArrayList(); for (int i = 0; i < TIMES; i++) // TODO add the value of the index variable i to the beginning of the ArrayList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void removeFirstArrayList(){ ArrayList list = new ArrayList(); for (int i = 0; i < TIMES; i++) list.add(i); long startTime = System.nanoTime(); for (int i = 0; i < TIMES; i++) // TODO remove the value of the index variable i from the end of the ArrayList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void removeLastArrayList(){ ArrayList list = new ArrayList(); for (int i = 0; i < TIMES; i++) list.add(i); long startTime = System.nanoTime(); for (int i = 0; i < TIMES; i++) // TODO remove the value of the index variable i from the beginning of the ArrayList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000;

System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void addLastLinkedList(){ long startTime = System.nanoTime(); LinkedList list = new LinkedList(); for (int i = 0; i < TIMES; i++) // TODO append the value of the index variable i to the end of the LinkedList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void addFirstLinkedList(){ long startTime = System.nanoTime(); LinkedList list = new LinkedList(); for (int i = 0; i < TIMES; i++) // TODO add the value of the index variable i to the beginning of the LinkedList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void removeLastLinkedList(){ LinkedList list = new LinkedList(); for (int i = 0; i < TIMES; i++) list.add(i); long startTime = System.nanoTime(); for (int i = 0; i < TIMES; i++) // TODO remove the value of the index variable i from the end of the LinkedList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void removeFirstLinkedList(){ LinkedList list = new LinkedList(); for (int i = 0; i < TIMES; i++) list.add(0, i); long startTime = System.nanoTime(); for (int i = 0; i < TIMES; i++) // TODO remove the value of the index variable i from the beginning of the LinkedList, named list long endTime = System.nanoTime(); long elapsedMS = (endTime - startTime) / 1000000; System.out.println("Elapsed time = " + elapsedMS + " milliseconds."); } public static void main(String[] argv){

System.out.println("Append in the end of an array list:"); addLastArrayList(); System.out.println("Insert in the beginning of an array list:"); addFirstArrayList(); System.out.println("Remove from the end of an array list:"); removeLastArrayList(); System.out.println("Remove from the beginning of an array list:"); removeFirstArrayList(); System.out.println("Append in the end of an linked list:"); addLastLinkedList(); System.out.println("Insert in the beginning of an linked list:"); addFirstLinkedList(); System.out.println("Remove from the end of a linked list:"); removeLastLinkedList(); System.out.println("Remove from the beginning of a linked list:"); removeFirstLinkedList(); }

Please do the TODOs correctly, please. Thank you.

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

Step: 3

blur-text-image

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions

Question

Describe alternative training and development delivery systems.

Answered: 1 week ago

Question

Summarize the learning organization idea as a strategic mind-set.

Answered: 1 week ago