Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ArrayTree -array(): E -count: int -size: int -order: int +Array Tree(order: int, capacity: int) +Array Tree() +root(): int +parent(p: int): int 2. Additional Instructions +child(p:

image text in transcribedimage text in transcribedimage text in transcribed

ArrayTree -array(): E -count: int -size: int -order: int +Array Tree(order: int, capacity: int) +Array Tree() +root(): int +parent(p: int): int 2. Additional Instructions +child(p: parent, c: int): int +size(): int 2.1. Basic Level: Array Tree ADT Develop an ArrayTree class to meet the design shown here. It should not implement +addRoot(e: E): int +isEmpty(): boolean the Tree interface we discussed in class. +get(pos: int): E The behavior of each method should be clear from our discussion in class. While the class is generic (element is type E), the positions are all primitive integers. The default +addChild(parent: int, child: int, e: E): int order is 2 and the default capacity is 1000. toString() should print a summary of+getChild(parent: int, child: int): E the data elements as shown in the sample output below: +toString(): String Running your ArrayTree with Test TreeADT.java should result in the following output. Note: it's ok that you get one Fail in testing a2. You should understand why that is correct as you implement the TreeADT. *** Test Array Tree ADT *** Pass: a1.isEmpty() Pass: a1.root() Pass: al.parent() Pass: a1.child() Pass: al.size() Pass: a1.isEmpty() Pass: al.get() Pass: a1.getChild() Small Tree: [ArrayTree: order-2, count-21, size=25, array={1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...)] Pass: a2.isEmpty() Pass: a2.root() Pass: a2.parent() Fail: a2.child(), expected 75, got -1 Pass: a2.size() Pass: a2.isEmpty() Pass: a2.get() Pass: a2.getChild() Large Tree: [ArrayTree: order-5, count=51, size-55, array-( 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 ....) Running your ArrayTree with Test TreeADT.java should result in the following output. Note: it's ok that you get one Fail in testing a2. You should understand why that is correct as you implement the TreeADT. *** Test ArrayTree ADT *** Pass: a1.isEmpty( Pass: a1.root) Pass: al.parent() Pass: a1.child() Pass: al.size() Pass: al.isEmpty() Pass: al.get() Pass: al.getChild() Small Tree: [ArrayTree: order-2, count=21, size=25, array=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... }] Pass: a2.isEmpty Pass: a2.root() Pass: a2.parent() Fail: a2.child(), expected 75, got -1 Pass: a2.size() Pass: a2.isEmpty() Pass: a2.get() Pass: a2.getChild() Large Tree: [ArrayTree: order-5, count=51, size=55, array={22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 ...)] 4 6 7 8 9 10 12 13 14 2 public class TestTreeADT { @ public static void main(String[] args) { ArrayTree a1 = new ArrayTree Integer>(2, 25); ArrayTree Integer> a2 = new ArrayTree Integer>(5, 55); int val = 1; System.out.println("*** Test ArrayTree ADT *** "); testcase("al.isEmpty()", al.isEmpty(?1 : , 1); 11 int pos = a1.addRoot(val++); for (int i = 0; i interface we discussed in class. +get(pos: int): E The behavior of each method should be clear from our discussion in class. While the class is generic (element is type E), the positions are all primitive integers. The default +addChild(parent: int, child: int, e: E): int order is 2 and the default capacity is 1000. toString() should print a summary of+getChild(parent: int, child: int): E the data elements as shown in the sample output below: +toString(): String Running your ArrayTree with Test TreeADT.java should result in the following output. Note: it's ok that you get one Fail in testing a2. You should understand why that is correct as you implement the TreeADT. *** Test Array Tree ADT *** Pass: a1.isEmpty() Pass: a1.root() Pass: al.parent() Pass: a1.child() Pass: al.size() Pass: a1.isEmpty() Pass: al.get() Pass: a1.getChild() Small Tree: [ArrayTree: order-2, count-21, size=25, array={1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...)] Pass: a2.isEmpty() Pass: a2.root() Pass: a2.parent() Fail: a2.child(), expected 75, got -1 Pass: a2.size() Pass: a2.isEmpty() Pass: a2.get() Pass: a2.getChild() Large Tree: [ArrayTree: order-5, count=51, size-55, array-( 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 ....) Running your ArrayTree with Test TreeADT.java should result in the following output. Note: it's ok that you get one Fail in testing a2. You should understand why that is correct as you implement the TreeADT. *** Test ArrayTree ADT *** Pass: a1.isEmpty( Pass: a1.root) Pass: al.parent() Pass: a1.child() Pass: al.size() Pass: al.isEmpty() Pass: al.get() Pass: al.getChild() Small Tree: [ArrayTree: order-2, count=21, size=25, array=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ... }] Pass: a2.isEmpty Pass: a2.root() Pass: a2.parent() Fail: a2.child(), expected 75, got -1 Pass: a2.size() Pass: a2.isEmpty() Pass: a2.get() Pass: a2.getChild() Large Tree: [ArrayTree: order-5, count=51, size=55, array={22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 ...)] 4 6 7 8 9 10 12 13 14 2 public class TestTreeADT { @ public static void main(String[] args) { ArrayTree a1 = new ArrayTree Integer>(2, 25); ArrayTree Integer> a2 = new ArrayTree Integer>(5, 55); int val = 1; System.out.println("*** Test ArrayTree ADT *** "); testcase("al.isEmpty()", al.isEmpty(?1 : , 1); 11 int pos = a1.addRoot(val++); for (int i = 0; i

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_2

Step: 3

blur-text-image_3

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 And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions