ASD Exercise 1

background image

BWS im. J. Tyszkiewicza , ASD Exercises 1

Exercise 1.

To the HighArray class add following methods:

a) getMax() – which returns the maximum element in the array or –1 if the

array is empty.

b) getMin() - which returns the minimum element in the array or –1 if the

array is empty.

c) removeMax()- which removes the maximum element in the array.

d) removeMin()- which removes the minimum element in the array.

e) isOrdered() – which returns TRUE when the array is ordered.

f) noDups() - which removes duplicates in the array.

g) Write an algorithm of ordering the arrays elements, which uses one of

the methods: removeMin() and uses an additionally array.

Exercise 2.

Write a program, which writes out a menu including a list of methods (as above)

and after choosing a number of the operation it will run it.

Follow the example below:

......

do{

System.out.println(" Operation on array " );

System.out.println("-----------------------------" );

System.out.println("1. Read elements " );

System.out.println("2. Choose random elements " );

System.out.println("3. Remove duplicates " );

System.out.println("4. Find element " );

System.out.println("5. Remove element " );

System.out.println("6. Maximum element " );

System.out.println("7. Remove maximum " );

System.out.println("8. Check order in array " );

System.out.println("9. Sort " );

System.out.println("0. End of program " );

System.out.println("-----------------------------" );

System.out.print(" Choose operation: " );

int op = (int) getLong();

switch (op) {

case 1: {

System.out.print("Give number of elements: ") ;

int n = (int) getLong();

while (arr.getnElems() < n )

background image

BWS im. J. Tyszkiewicza , ASD Exercises 2

{

System.out.print("Give element: ") ;

el= getLong();

if (arr.find(el)==false)

arr.insert(el);

}

arr.display();
break;

}

……

Exercise 3. (First program)

Write a program, which illustrates following operations:

,

, / ,

, = on sets

represented in arrays. The program should contain a class called Set, which

includes methods: Insert, Find, Display and a class called SetApp, which includes

methods: Sum, Product, Difference, Inclusion, Equality.

Ex.

C = A

B

C = A

B

C = A/B

A

B ?

A = B ?




Wyszukiwarka

Podobne podstrony:
ASD Exercise 2
ASD Exercise 3
ASD Exercise 2
ASD od z Sawanta II Wykład17 6
B06 exercise05 2 DJ
CLE Grammaire Progressive du Francais avec 400 exercices (niveau debutant volume2 CORRIGES)
ASD 2012 test6
nw asd w13
Chinese character writing Exercise sheets 2
teoria asd, stud, II semestr, ASD
Exercises in morphology, part 3
asd
test Exercise 6 Prepositions
Exercise List #4
ASD w5
Progressing from imitative to creative exercises
ASD w12

więcej podobnych podstron