
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
![1
import numpy as np
from Interfaces import List
3
4 v class ArrayList (List):
5
6
ArrayList: Implementation of a List interface using Arrays.
7
8 v
def _init_ (self):
9
10
-_init_: Initialize the state (array, n and j).
11
12
self.n = e
self.j = e
self.a = self.new_array (1)
13
14
15
16 v
def new_array (self, n : int) ->np.array:
17
18
new_array: Create a new array of size n
Input:
19
20
n: the size of the new array
21
Return:
22
An array of size n
23
24
return np.zeros (n, np.object)
25
26 v
def resize(self):
27
28
resize
Create a new array and copy the old values.
29
30
pass
31
32 y
def get (self, i : int) -> object:
33
34
get: returns the element at position i
35
Inputs:
36
i: Index that is integer non negative and at most n
37
38
pass
39
40 v
def set (self, i : int, x : object) -> object:
41
42
set: Set the value x at the indexi.
43
Inputs:
44
i: Index that is integer non negative and at most n
45
x: Object type, i.e., any object
46
47
pass
48
49
def append (self, x : object) :
y
50
self.add (self.n, x)
51
52 v
def add (self, i : int, x : object) :
53
54
add: shift one position all the items j>=i, insert an element
55
at position_i of the list and increment the number of elements
56
in the list
57
Inputs:
i: Index that is integer non negative and at most n
x: Object type, i.e., any object
58
59
60
...
61
pass
62
63 v
def remove (self, i : int) -> object:
64
pass
65
66 v
def size(self) -> int:
67
return self.n
68
69 v
def str_(self):
70
for i in range (0, self.n):
s += "%r" % self.a[ (i + self.j) % len (self.a)]
if i < self.n-1:
71 v
72
73 y
74
s +=","
75
return s +)](https://content.bartleby.com/qna-images/question/5cc32607-3a96-40ee-84c8-a275278c96cb/638f3181-5ef6-479c-bb13-3df22bd6af7f/84cudpf_thumbnail.png)
Transcribed Image Text:1
import numpy as np
from Interfaces import List
3
4 v class ArrayList (List):
5
6
ArrayList: Implementation of a List interface using Arrays.
7
8 v
def _init_ (self):
9
10
-_init_: Initialize the state (array, n and j).
11
12
self.n = e
self.j = e
self.a = self.new_array (1)
13
14
15
16 v
def new_array (self, n : int) ->np.array:
17
18
new_array: Create a new array of size n
Input:
19
20
n: the size of the new array
21
Return:
22
An array of size n
23
24
return np.zeros (n, np.object)
25
26 v
def resize(self):
27
28
resize
Create a new array and copy the old values.
29
30
pass
31
32 y
def get (self, i : int) -> object:
33
34
get: returns the element at position i
35
Inputs:
36
i: Index that is integer non negative and at most n
37
38
pass
39
40 v
def set (self, i : int, x : object) -> object:
41
42
set: Set the value x at the indexi.
43
Inputs:
44
i: Index that is integer non negative and at most n
45
x: Object type, i.e., any object
46
47
pass
48
49
def append (self, x : object) :
y
50
self.add (self.n, x)
51
52 v
def add (self, i : int, x : object) :
53
54
add: shift one position all the items j>=i, insert an element
55
at position_i of the list and increment the number of elements
56
in the list
57
Inputs:
i: Index that is integer non negative and at most n
x: Object type, i.e., any object
58
59
60
...
61
pass
62
63 v
def remove (self, i : int) -> object:
64
pass
65
66 v
def size(self) -> int:
67
return self.n
68
69 v
def str_(self):
70
for i in range (0, self.n):
s += "%r" % self.a[ (i + self.j) % len (self.a)]
if i < self.n-1:
71 v
72
73 y
74
s +=","
75
return s +)
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- What are the methods for evaluating the efficiency of an ArrayList?arrow_forwardExplain the fundamental difference between an array and an arraylist.arrow_forwardJava 1. Implement ArrayUnorderedList<T> class which will extend ArrayList<T> by defining the following additional methods(i) public void addToFront(T element); //Adds the specified element to the front of the list.(ii) public void addToRear(T element); //Adds the specified element to the rear of the list.(iii) public void addAfter(T element, T target); //Adds the specified element after the specified target element.a. Create an object of ArrayUnorderedList<T> class and perform some add, remove, and search operations and finally print the entire Stack.arrow_forward
- How can the performance of an ArrayList be measured?arrow_forwardjava This method gets an Arraylist of Integers and a number(Integer). It returns an Arraylist. It removes any instance of the given number from the Arraylist. Example: romoveInst([1,1,2,3,1,4],1) returns: [2,3,4] romoveInst([3,4,3,3],4) returns: [3,3,3] public static ArrayList<Integer> removeInst(ArrayList<Integer> r,Integer n) public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); int n = in.nextInt(); ArrayList<Integer> list = new ArrayList<>(); for(int i=0; i < size; i++) { list.add(in.nextInt()); } System.out.println(removeInst(list, n)); } }arrow_forwardHow can an ArrayList be used?arrow_forward
- Create a Generic Class Assignment Instructions Overview It would be nice if we could write a single sort method to sort the elements in an Integer array, a String array or an array of any type that supports ordering (i.e., its elements can be compared). It would also be nice if we could write a single Stack class that could be used as a Stack of integers, a Stack of floating-point numbers, a Stack of Strings or a Stack of any other type. It would be even nicer if we could detect type mismatches at compile time—known as compile-time type safety. Generic methods and generic classes provide the means to create the type-safe general models mentioned above. Instructions Write a generic class Pair which has two type parameters—F and S—each representing the type of the first and second element of the pair, respectively. Add set and get methods for the first and second elements of the pair and be sure to demonstrate your setters/getters actually work. (Hint: The class header should be public…arrow_forwardThe text's array-based list implementation stores elements in the lowest possible indices of the array. True or False screen shot shows the text's array based listarrow_forwardpackage edu.umsl.iterator;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Iterator;public class Main {public static void main(String[] args) {String[] cities = {"New York", "Atlanta", "Dallas", "Madison"};Collection<String> stringCollection = new ArrayList<>(Arrays.asList(cities));Iterator<String> iterator = stringCollection.iterator();while (iterator.hasNext()) {System.out.println(/* Fill in here */);}}} Rewrite the while loop to print out the collection using an iterator. Group of answer choices iterator.toString() iterator.getClass(java.lang.String) iterator.remove() iterator.next()arrow_forward
- The two classes you will create will implement the operations defined in the interface as shown in the UML class diagram above. In addition, BinarySearchArray will implement a static method testBinarySearchArray() that populates the lists, and lets the user interactively test the two classes by adding and removing elements. The parameter BinarySearch can represent either class and tells testBinarySearchArray which class to test. Steps to Implement: 1) To get started create a new project in IntelliJ called BinarySearch. Add a class to your project called BinarySearchArray. Then add another class BinarySearchArrayList and an interface called BinarySearch. The interface BinarySearch includes public method stubs as shown in the diagram. You are allowed to add BinarySearchArrayList to the same file as BinarySearch but don't add an access modifier to this class, or for easier reading, you can declare the classes in separate files with public access modifiers. Only the class…arrow_forwardpublic class PokerAnalysis implements PokerAnalyzer { privateList<Card>cards; privateint[]rankCounts; privateint[]suitCounts; /** * The constructor has been partially implemented for you. cards is the * ArrayList where you'll be adding all the cards you're given. In addition, * there are two arrays. You don't necessarily need to use them, but using them * will be extremely helpful. * * The rankCounts array is of the same length as the number of Ranks. At * position i of the array, keep a count of the number of cards whose * rank.ordinal() equals i. Repeat the same with Suits for suitCounts. For * example, if your Cards are (Clubs 4, Clubs 10, Spades 2), your suitCounts * array would be {2, 0, 0, 1}. * * @param cards * the list of cards to be added */ publicPokerAnalysis(List<Card>cards){ this.cards=newArrayList<Card>(); this.rankCounts=newint[Rank.values().length]; this.suitCounts=newint[Suit.values().length];…arrow_forwardHow can the performance of an ArrayList be evaluated?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY