(Directory size) Listing 18.10, DirectorySize.java, gives a recursive method for finding a directory size. Rewrite this method without using recursion. Your
long getSize(File directory) {
long size = 0;
add directory to the queue;
while (queue is not empty) {
Remove an item from the queue into t;
if (t is a file)
size += t.1ength();
else
add all the files and subdirectories under t into the
queue ;
}
return size;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Additional Engineering Textbook Solutions
Concepts Of Programming Languages
Starting Out With Visual Basic (8th Edition)
Starting Out with C++: Early Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- (Online Address Book revisited) Programming Exercise 5 in Chapter 11 could handle a maximum of only 500 entries. Using linked lists, redo the program to handle as many entries as required. Add the following operations to your program: Add or delete a new entry to the address book. Allow the user to save the data in the address book.arrow_forward(Generic binary search) Implement the following method using binary search. public static <E extends Comparable<E>> int binarySearch(E[] list, E key) Note:- Please type this java code fully running and also need an output for this given code.arrow_forwarddef removeMultiples(x, arr) - directly remove the multiples of prime numbers (instead of just marking them) by creating a helper function. This recursive function takes in a number, n, and a list and returns a list that doesn’t contain the multiples of n.def createList(n) - a recursive function, createList(), that takes in the user input n and returns an array of integers from 2 through n (i.e. [2, 3, 4, …, n]). def Sieve_of_Eratosthenes(list) - a recursive function that takes in a list and returns a list of prime numbers from the input list.Template below: def createList(n): #Base Case/s #ToDo: Add conditions here for base case/s #if <condition> : #return <value> #Recursive Case/s #ToDo: Add conditions here for your recursive case/s #else: #return <operation and recursive call> #remove the line after this once all ToDo is completed return [] def removeMultiples(x, arr): #Base Case/s #TODO: Add conditions here for your…arrow_forward
- #python codecoud you provide comments and little explanation it would really help me to understandthankyouarrow_forwardjava: // Class to do MergeSort and QuickSort on int arrays and test them public class MergeQuickSorts { // Create a main to test MergeSort and QuickSort for // three cases - Sorted Aray, Reverse Sorted Array, Random Array // Each array should be size 50 // For the sorted array use the entries 1, 2, 3......50 // For the reverse sorted array use the entries 50, 49, 48.....1 // For the random array use ints between 1 and 50 inclusive, duplicates allowed // For each of the 6 sorts print the array before and after the sort // and show clearly which sort is being done public static void main(String[] args) { }arrow_forwardplease code in python Forbidden concepts: arrays/lists (data structures), recursion, custom classes Create a program that takes a password string from the user and encrypts the letters to go up or down the alphabet using a triple-number key. The amount up or down for the encryption of the alphabetical characters will depend on the input from the user. Input for the encryption key integers will be -25 ≤ key ≤ 25.For example, ‘CHICKEN’ with a 1, 2, -3 would be C up 1 to D, H up 2 to J, I down 3 to F,then C up 1 to D, K up 2 to M, E down 3 to B, and N up 1 to O. Thus the encryption becomes ‘DJFDMBO’.arrow_forward
- /** numUnique returns the number of unique values in an array of doubles. * The array may be empty and it may contain duplicate values. * Unlike the previous questions, you can assume the array is sorted. * * Your solution should contain at most one loop. You may not use recursion. * Your solution must not call any other functions. * Here are some examples (using "==" informally): * * * * * Ⓒ == numUnique (new double[] { }) 1 == numUnique (new double[] {11}) 1 == numUnique (new double[] { 11, 11, 11, 11 }) 8 == numUnique (new double[] { 11, 11, 11, 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88, 88 }) 8 == numUnique (new double[] { 11, 22, 33, 44, 44, 44, 44, 44, 55, 55, 66, 77, 88 }) * */ public static int numUnique (double[] list) { return StdRandom.uniform (100); //TODO: fix thisarrow_forward(Sort ArrayList) Write the following method that sorts an ArrayList: public static <E extends Comparable<E>> void sort(ArrayList<E> list) Write a test program that prompts the user to enter 10 integers, invokes this method to sort the numbers, and displays the numbers in increasing order. Sample Run Enter 10 integers: 3 4 12 7 3 4 5 6 4 7 The sorted numbers are 3 3 4 4 4 5 6 7 7 12 Class Name: Exercise19_09arrow_forwardNEED HELP WITH 2-D list. (PYTHON) For e.g., the following is another example of 2-D multidimensional list. Each row contains student name followed by their grades in 5 subjects: students = [ ['Anna', 98.5, 77.5, 89, 93.5, 85.5], ['Bob', 77, 66.5, 54, 90, 85.5], ['Sam', 98, 97, 89.5, 92.5, 96.5] ] To access, a specific row, you would use students[row_number][column_number]. students[0][0] would print 'Anna' students[0][1] would print 98.5 Create your own 2-D list with at-least 5 students and their grades in 5 subjects like the example above. Write a nested for/while loop that would use find the total of 5 subjects for each student and stores that into a sepearate list. Display the Total for each student.arrow_forward
- Instructions: Implement a merge sort in Java, creating a class to hold the main method as well as the mergesort method (which should be a static method). The mergesort method should be able to use any Collection object and it should return a Collection that contains the contents of the original Collection, but in sorted order. The program must ask the user for the data to sort, using numeric data in this case, but your mergesort method must be capable of working with any Collection of Comparable objects. Use recursion.arrow_forwardapartmentList is a pointer to the first node in a linked list of nodes. Use this for Parts a, b, and c. Part a. Create an inner class that will hold the following information: the apartment number of the apartment (an int), the number of bedrooms in the apartment (also an int), the current rent of the apartment (a double). Don't forget to include a field for the link! Just create the class itself and the instance variables; you don't need to put any methods into the class.arrow_forwardProgramming language: Java Topic: linked listarrow_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