Exercises/list/Main.java

100 lines
2.2 KiB
Java
Raw Permalink Normal View History

2025-03-16 07:52:49 +01:00
package de.vivi.list;
public class Main {
public static void main(String[] args) {
ByteList array = new ArrayByteList();
array.add("Hi");
System.out.println(array);
/*ByteList linked = new LinkedByteList();
ByteList combined = new CombinedByteList(16);
*/
//testList(array);
/*testList(linked);
testList(combined);
testSort(array);
testSort(linked);
testSort(combined);
*/
}
private static void testList(ByteList list) {
// add the element at the end
list.add((byte) 10);
list.add((byte) 5);
list.add((byte) -86);
list.add((byte) 3);
// list: [10, 5, -86, 3]
// add the element at the specified index
/* list.add(3, (byte) 99);
list.add(2, (byte) -40);
// list: [10, 5, -40, -86, 99, 3]
// remove the element at the specified index
list.remove(2);
list.remove(3);
// list: [10, 5, -86, 3]
// set the element at the specified index
list.set(1, (byte) 43);
list.set(0, (byte) 8);
// list: [8, 43, -86, 3]
// get the element at the specified index
list.get(2); // returns: -86
list.get(1); // returns: 43
// get the size
list.size(); // returns: 4
// does the list contain the specified element?
list.contains(43); // returns: true
list.contains(4); // returns: false
// return a string of the form: [1, 84, 53]
list.toString(); // returns: "[8, 43, -86, 3]"
// return a copy of the list
list.copy(); // returns: [8, 43, -86, 3]
// remove all elements inside the list
list.clear();
// list: []
// allow to use for each loop on list
for (byte value : list) {
// do some stuff with value...
}
*/
}
/*private static void testSort(ByteList list) {
ByteSort bubble = new BubbleSort();
ByteSort merge = new MergeSort();
ByteSort bogo = new BogoSort();
// sort the lists with the sorting algorithm
bubble.sort(list.copy());
merge.sort(list.copy());
bogo.sort(list.copy());
}
*/
}