updated README
This commit is contained in:
@@ -185,20 +185,93 @@ public class Liste<T>
|
|||||||
|
|
||||||
while ((currentLink != null))
|
while ((currentLink != null))
|
||||||
{
|
{
|
||||||
|
System.out.println("yote");
|
||||||
if(currentLink.daten.equals(opfer)){
|
if(currentLink.daten.equals(opfer)){
|
||||||
if(currentLink == anfang){
|
if(currentLink == anfang){
|
||||||
anfang = currentLink.naechster;
|
anfang = currentLink.naechster;
|
||||||
|
System.out.println("anfang");
|
||||||
}else if(currentLink == ende) {
|
}else if(currentLink == ende) {
|
||||||
before.naechster = null;
|
before.naechster = null;
|
||||||
ende = before;
|
ende = before;
|
||||||
|
System.out.println("ende");
|
||||||
}else {
|
}else {
|
||||||
before.naechster = currentLink.naechster;
|
before.naechster = currentLink.naechster;
|
||||||
|
System.out.println("mitte");
|
||||||
|
}
|
||||||
|
anzGeloeschte++;
|
||||||
|
}
|
||||||
|
before = currentLink;
|
||||||
|
currentLink = currentLink.naechster;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return anzGeloeschte;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int entferneWerte2(final T opfer)
|
||||||
|
{
|
||||||
|
int anzGeloeschte = 0;
|
||||||
|
Link<T> currentLink = anfang;
|
||||||
|
Link<T> before = new Link<T>(null,null);
|
||||||
|
|
||||||
|
while ((currentLink != null))
|
||||||
|
{
|
||||||
|
System.out.println("yote");
|
||||||
|
if(currentLink.daten.equals(opfer)){
|
||||||
|
if(currentLink == anfang){
|
||||||
|
anfang = currentLink.naechster;
|
||||||
|
System.out.println("anfang");
|
||||||
|
}else if(currentLink == ende) {
|
||||||
|
before.naechster = null;
|
||||||
|
ende = before;
|
||||||
|
System.out.println("ende");
|
||||||
|
}else {
|
||||||
|
before.naechster = currentLink.naechster;
|
||||||
|
System.out.println("mitte");
|
||||||
}
|
}
|
||||||
anzGeloeschte++;
|
anzGeloeschte++;
|
||||||
}
|
}
|
||||||
before = currentLink;
|
before = currentLink;
|
||||||
currentLink = currentLink.naechster;
|
currentLink = currentLink.naechster;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return anzGeloeschte;
|
return anzGeloeschte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public T delete(int position)
|
||||||
|
{
|
||||||
|
// Wenn die Liste leer oder die position < 0 ist, wird kein Element
|
||||||
|
// entfernt
|
||||||
|
if (istLeer() || (position < 0))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Wenn die position 0 ist, wird am Anfang der Liste gel<65>scht
|
||||||
|
if (position == 0)
|
||||||
|
return entfernen();
|
||||||
|
|
||||||
|
// VORG<52>NGER ZUR POSITION FINDEN
|
||||||
|
// Bei einer leeren Liste oder f<>r position==0 gibt es keinen Vorg<72>nger;
|
||||||
|
// genau diese F<>lle wurden oben bereits behandelt. Es gibt aber auch
|
||||||
|
// keinen Vorg<72>ner, wenn position zu gro<72> ist! In diesem Fall wird das
|
||||||
|
// letzte Element NICHT Vorg<72>nger, damit nur tats<74>chlich existierende
|
||||||
|
// Elemente aus der Liste entfernt werden.
|
||||||
|
Link<T> vorgaenger = anfang;
|
||||||
|
|
||||||
|
while ((--position > 0) && (vorgaenger != null))
|
||||||
|
vorgaenger = vorgaenger.naechster;
|
||||||
|
|
||||||
|
// Gibt es ein Element zum l<>schen?
|
||||||
|
if ((vorgaenger == null) || (vorgaenger.naechster == null))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
final T opfer = vorgaenger.naechster.daten;
|
||||||
|
|
||||||
|
// Element l<>schen und ggf. ende anpassen beim L<>schen des letzten
|
||||||
|
// Listen-Elements
|
||||||
|
if ((vorgaenger.naechster = vorgaenger.naechster.naechster) == null)
|
||||||
|
ende = vorgaenger;
|
||||||
|
|
||||||
|
return opfer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
72
AuD/src/UEB04/Aufgabe3/ListInterfaceAufgabe.java
Normal file
72
AuD/src/UEB04/Aufgabe3/ListInterfaceAufgabe.java
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
package UEB04.Aufgabe3;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class ListInterfaceAufgabe
|
||||||
|
{
|
||||||
|
// Elemente in Liste einfgen
|
||||||
|
static void fillList(List<String> list)
|
||||||
|
{
|
||||||
|
// Zahlen von 0 bis 20 als Zeichenketten (Strings) einfgen
|
||||||
|
for (int a = 0; a <= 20; a++)
|
||||||
|
list.add("" + a);
|
||||||
|
|
||||||
|
// Element an der Position 3 entfernen
|
||||||
|
list.remove(3);
|
||||||
|
|
||||||
|
// Erstes Element in der Liste entfernen, das gleich "6" ist
|
||||||
|
list.remove("6");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Liste vom Anfang bis zum Ende mit einer
|
||||||
|
// foreach-Schleife iterieren und Elemente ausgeben
|
||||||
|
static void printList(List<String> list)
|
||||||
|
{
|
||||||
|
for(String s:list){
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alle Elemente aus der Liste entfernen, die durch 5 teilbar sind
|
||||||
|
static void remove5List(List<String> list)
|
||||||
|
{
|
||||||
|
Iterator i = list.iterator();
|
||||||
|
int counter = 0;
|
||||||
|
while( i.hasNext()){
|
||||||
|
if (Integer.parseInt((String) i.next())%5==0){
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
// Erzeugen der LinkedList
|
||||||
|
LinkedList<String> list1 = new LinkedList<String>();
|
||||||
|
fillList(list1);
|
||||||
|
System.out.println("\nAusgabe der ersten Liste(list1)");
|
||||||
|
printList(list1);
|
||||||
|
|
||||||
|
remove5List(list1);
|
||||||
|
System.out.println("\nlist1 nach dem Entfernen der durch 5 teilbaren Zahlen");
|
||||||
|
printList(list1);
|
||||||
|
|
||||||
|
// Erzeugen der ArrayList
|
||||||
|
ArrayList<String> list2 = new ArrayList<String>();
|
||||||
|
fillList(list2);
|
||||||
|
|
||||||
|
System.out.println("\nAusgabe der zweiten Liste(list2)");
|
||||||
|
printList(list2);
|
||||||
|
|
||||||
|
System.out.println("\nAusgabe der dritten Liste(list2)");
|
||||||
|
List<String> list3 = list2.subList(5,12);
|
||||||
|
printList(list3);
|
||||||
|
list3.remove("11");
|
||||||
|
System.out.println("\n");
|
||||||
|
printList(list3);
|
||||||
|
|
||||||
|
System.out.println("\nAusgabe der zweiten Liste(list2)");
|
||||||
|
printList(list2);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
65
AuD/src/UEB04/Aufgabe4/ArrayStack.java
Normal file
65
AuD/src/UEB04/Aufgabe4/ArrayStack.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package UEB04.Aufgabe4;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ArrayStack<E> implements StackI<E>
|
||||||
|
{
|
||||||
|
// Array, in dem die Elemente des Stacks gespeichert werden.
|
||||||
|
// Das oberes Ende des Stacks liegt an Position pos-1.
|
||||||
|
// Ein Array mit Elementen vom Typ E kann zwar deklariert, aber
|
||||||
|
// nicht <20>ber new erzugt werden (Java-Mangel)!
|
||||||
|
private Object[] st;
|
||||||
|
|
||||||
|
// N<>chste freie Position im Array
|
||||||
|
// Gleichzeitig Anzahl der im Array/Stack gespeicherten Elemente
|
||||||
|
private int pos;
|
||||||
|
List<E> yeet = new ArrayList<E>();
|
||||||
|
|
||||||
|
// Erzeugt ein Stack-Objekt, in dem maximal size Elemente
|
||||||
|
// abgespeichert werden k<>nnen
|
||||||
|
public ArrayStack(int size)
|
||||||
|
{
|
||||||
|
st = new Object[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Legt <20>bergebenes Element auf den Stack, sofern noch Platz
|
||||||
|
// vorhanen ist. Das Element wird an Position pos gespeichert.
|
||||||
|
public void push(E element)
|
||||||
|
{
|
||||||
|
st[size() +1] = element;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Holt oberstes Element vom Stack, sofern der Stack nicht leer ist.
|
||||||
|
public E pop()
|
||||||
|
{
|
||||||
|
E element = top();
|
||||||
|
st[size()]=null;
|
||||||
|
return element;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gibt oberstes Element auf dem Stack zur<75>ck, sofern der Stack nicht
|
||||||
|
// leer ist. Bei leerem Stack wird null zur<75>ckgegeben.
|
||||||
|
public E top()
|
||||||
|
{
|
||||||
|
return (E) st[size()];
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size(){
|
||||||
|
int counter = 0;
|
||||||
|
while (st[counter]!=null){
|
||||||
|
if(st.length == counter){
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gibt true zur<75>ck, falls der Stack leer ist
|
||||||
|
public boolean isEmpty()
|
||||||
|
{
|
||||||
|
return st[0]==null;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
AuD/src/UEB04/Aufgabe4/StackI.java
Normal file
9
AuD/src/UEB04/Aufgabe4/StackI.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package UEB04.Aufgabe4;// Abstrakte Datenstruktur Stack, realisiert als Java-Interface
|
||||||
|
|
||||||
|
interface StackI<E>
|
||||||
|
{
|
||||||
|
public void push(E element);
|
||||||
|
public E pop();
|
||||||
|
public E top();
|
||||||
|
public boolean isEmpty();
|
||||||
|
}
|
||||||
39
AuD/src/UEB04/Aufgabe4/StackTest.java
Normal file
39
AuD/src/UEB04/Aufgabe4/StackTest.java
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package UEB04.Aufgabe4;
|
||||||
|
|
||||||
|
public class StackTest
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
ArrayStack<Integer> st = new ArrayStack<Integer>(10);
|
||||||
|
|
||||||
|
System.out.println("Ablegen auf dem Stapel: 5 Elemente");
|
||||||
|
for (int a = 1; a <= 5; a++)
|
||||||
|
{
|
||||||
|
System.out.print(a + " ");
|
||||||
|
st.push(a);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("Entnehmen vom Stapel: 3 Elemente");
|
||||||
|
for (int a = 1; a <= 3; a++)
|
||||||
|
{
|
||||||
|
System.out.print(st.pop() + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("Versuch: Ablegen auf dem Stapel: 10 Elemente");
|
||||||
|
for (int a = 6; a <= 15; a++)
|
||||||
|
{
|
||||||
|
System.out.print(a + " ");
|
||||||
|
st.push(a);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("Entnehmen vom Stapel bis Stapel leer");
|
||||||
|
while (!st.isEmpty())
|
||||||
|
{
|
||||||
|
System.out.print(st.pop() + " ");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
BIN
out/production/AuD/UEB04/Aufgabe3/ListInterfaceAufgabe.class
Normal file
BIN
out/production/AuD/UEB04/Aufgabe3/ListInterfaceAufgabe.class
Normal file
Binary file not shown.
BIN
out/production/AuD/UEB04/Aufgabe4/ArrayStack.class
Normal file
BIN
out/production/AuD/UEB04/Aufgabe4/ArrayStack.class
Normal file
Binary file not shown.
BIN
out/production/AuD/UEB04/Aufgabe4/StackI.class
Normal file
BIN
out/production/AuD/UEB04/Aufgabe4/StackI.class
Normal file
Binary file not shown.
BIN
out/production/AuD/UEB04/Aufgabe4/StackTest.class
Normal file
BIN
out/production/AuD/UEB04/Aufgabe4/StackTest.class
Normal file
Binary file not shown.
Reference in New Issue
Block a user