Initial sharing of project
commit
aa06e9a9bd
|
@ -0,0 +1,86 @@
|
|||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse LinkedList.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class LinkedList<T>
|
||||
{
|
||||
public Node<T> first;
|
||||
public LinkedList(){
|
||||
}
|
||||
|
||||
public void einfuegen (T neu) {
|
||||
Node<T> n = new Node<T>(neu);//Neue Node mit Zahl "neu " anlegen
|
||||
|
||||
//Überprüfe ob die liste leer ist
|
||||
if(first == null){
|
||||
//setze neue node als erster Eintrag
|
||||
first = n;
|
||||
}
|
||||
else {
|
||||
Node<T> current = first;
|
||||
|
||||
while(current.next != null){
|
||||
current = current.next;
|
||||
}
|
||||
current.setNext(n);
|
||||
}
|
||||
|
||||
//current ist jetzt der letzte Eintrag
|
||||
//setze neue Node als Nachfolger von bisher letztem Eintrag
|
||||
}
|
||||
|
||||
public int laenge(){
|
||||
Node current = first;
|
||||
int laenge = 0;
|
||||
while(current != null){
|
||||
current = current.next;
|
||||
laenge++;
|
||||
}
|
||||
return laenge;
|
||||
|
||||
}
|
||||
|
||||
public T getNteZahl(int n){
|
||||
Node<T> current = first;
|
||||
for(int i = 0; i<n; i++){
|
||||
current = current.next;
|
||||
}
|
||||
return current.wert;
|
||||
}
|
||||
|
||||
public void loesche(int n){
|
||||
Node<T> current = first;
|
||||
|
||||
//gehe an den Vorgänger des zu löschenden Eintrags
|
||||
for(int i=0; i<n-1; i++){
|
||||
current = current.next;
|
||||
}
|
||||
//setze Übernächsten Eintrag als Nachfolger
|
||||
current.next = current.next.next;
|
||||
|
||||
}
|
||||
|
||||
public void hinzufügen(int n, T wert){
|
||||
|
||||
Node<T> neu = new Node<T>(wert);
|
||||
if(n==0){
|
||||
//setze Nachfolger auf bisherigen Stand
|
||||
neu.setNext(first);
|
||||
//setze neuen Start auf neuen
|
||||
first = neu;
|
||||
}else{
|
||||
Node<T> current = first;
|
||||
//gehe an den Vorgänger des zu löschenden Eintrags
|
||||
for(int i=0; i<n-1; i++){
|
||||
current = current.next;
|
||||
}
|
||||
//setze Übernächsten Eintrag als Nachfolger
|
||||
current.next = current.next.next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse List.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class List<T>
|
||||
{
|
||||
public Node<T> first;
|
||||
public List(){
|
||||
}
|
||||
|
||||
public void einfuegen (T neu) {
|
||||
Node<T> n = new Node<T>(neu);//Neue Node mit Zahl "neu " anlegen
|
||||
|
||||
//Überprüfe ob die liste leer ist
|
||||
if(first == null){
|
||||
//setze neue node als erster Eintrag
|
||||
first = n;
|
||||
}
|
||||
else {
|
||||
Node<T> current = first;
|
||||
|
||||
while(current.next != null){
|
||||
current = current.next;
|
||||
}
|
||||
current.setNext(n);
|
||||
}
|
||||
|
||||
//current ist jetzt der letzte Eintrag
|
||||
//setze neue Node als Nachfolger von bisher letztem Eintrag
|
||||
}
|
||||
|
||||
public int laenge(){
|
||||
Node current = first;
|
||||
int laenge = 0;
|
||||
while(current != null){
|
||||
current = current.next;
|
||||
laenge++;
|
||||
}
|
||||
return laenge;
|
||||
|
||||
}
|
||||
|
||||
public T getNteZahl(int n){
|
||||
Node<T> current = first;
|
||||
for(int i = 0; i<n; i++){
|
||||
current = current.next;
|
||||
}
|
||||
return current.wert;
|
||||
}
|
||||
|
||||
public void loesche(int n){
|
||||
Node<T> current = first;
|
||||
|
||||
//gehe an den Vorgänger des zu löschenden Eintrags
|
||||
for(int i=0; i<n-1; i++){
|
||||
current = current.next;
|
||||
}
|
||||
//setze Übernächsten Eintrag als Nachfolger
|
||||
current.next = current.next.next;
|
||||
|
||||
}
|
||||
|
||||
public void hinzufügen(int n, T wert){
|
||||
|
||||
Node<T> neu = new Node<T>(wert);
|
||||
if(n==0){
|
||||
//setze Nachfolger auf bisherigen Stand
|
||||
neu.setNext(first);
|
||||
//setze neuen Start auf neuen
|
||||
first = neu;
|
||||
}else{
|
||||
Node<T> current = first;
|
||||
//gehe an den Vorgänger des zu löschenden Eintrags
|
||||
for(int i=0; i<n-1; i++){
|
||||
current = current.next;
|
||||
}
|
||||
//setze Übernächsten Eintrag als Nachfolger
|
||||
current.next = current.next.next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse Menge.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class Menge<T>
|
||||
{
|
||||
public Node<T> first;
|
||||
public Menge(){
|
||||
}
|
||||
|
||||
public boolean contains(T n){
|
||||
Node<T> current = first;
|
||||
while (current != null){
|
||||
if(current.wert == n){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void add (T neu) {
|
||||
Node<T> n = new Node<T>(neu);//Neue Node mit Zahl "neu " anlegen
|
||||
|
||||
if(contains(neu) == false){//Überprüfe ob die liste leer ist
|
||||
if(first == null){
|
||||
//setze neue node als erster Eintrag
|
||||
first = n;
|
||||
}
|
||||
else {
|
||||
Node<T> current2 = first;
|
||||
|
||||
while(current2.next != null){
|
||||
current2 = current2.next;
|
||||
}
|
||||
current2.setNext(n);
|
||||
}
|
||||
|
||||
//current ist jetzt der letzte Eintrag
|
||||
//setze neue Node als Nachfolger von bisher letztem Eintrag
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(T neu){
|
||||
Node<T> n = new Node<T>(neu);
|
||||
Node<T> current = first;
|
||||
while(current.next.wert != n){
|
||||
current = current.next;
|
||||
}
|
||||
current.next = current.next.next;
|
||||
}
|
||||
public Menge<T> intersection(Menge<T> s){
|
||||
Menge<T> neu = new Menge<T>();
|
||||
Node<T> current = first;
|
||||
while(current != null){
|
||||
current = current.next;
|
||||
if(s.contains(current.wert) == true){
|
||||
neu.add(current.wert);
|
||||
|
||||
}
|
||||
}
|
||||
return neu;
|
||||
}
|
||||
public Menge<T> union(Menge<T> s){
|
||||
Menge<T> neu = new Menge<T>();
|
||||
Node<T> current = first;
|
||||
while(current != null){
|
||||
neu.add(current.wert);
|
||||
current = current.next;
|
||||
}
|
||||
Node<T> current2 = first;
|
||||
while(current != null){
|
||||
neu.add(current2.wert);
|
||||
current = current.next;
|
||||
}
|
||||
return neu;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse Node.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class Node<T>
|
||||
{
|
||||
|
||||
public T wert;
|
||||
|
||||
public Node<T> next;
|
||||
|
||||
public Node(T z){
|
||||
wert = z;
|
||||
}
|
||||
public void setNext(Node n){
|
||||
next = n;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse Queue.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class Queue<T>
|
||||
{
|
||||
public Node<T> first;
|
||||
|
||||
public Queue(){
|
||||
}
|
||||
public boolean isEmpty(){
|
||||
if(first == null){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void enqueue (T neu) {
|
||||
Node<T> r = new Node<T>(neu);//Neue Node mit Zahl "neu " anlegen
|
||||
|
||||
//Überprüfe ob die liste leer ist
|
||||
if(first == null){
|
||||
//setze neue node als erster Eintrag
|
||||
first = r;
|
||||
}
|
||||
else {
|
||||
Node<T> current = first;
|
||||
|
||||
while(current.next != null){
|
||||
current = current.next;
|
||||
}
|
||||
current.setNext(r);
|
||||
}
|
||||
|
||||
//current ist jetzt der letzte Eintrag
|
||||
//setze neue Node als Nachfolger von bisher letztem Eintrag
|
||||
}
|
||||
|
||||
public int laenge(){
|
||||
Node current = first;
|
||||
int laenge = 0;
|
||||
while(current != null){
|
||||
current = current.next;
|
||||
laenge++;
|
||||
}
|
||||
return laenge;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public T dequeue(){
|
||||
if(first == null){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
Node<T> current = first;
|
||||
first = first.next;
|
||||
return current.wert;
|
||||
}
|
||||
|
||||
}
|
||||
public T front(){
|
||||
|
||||
return first.wert;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
------------------------------------------------------------------------
|
||||
Dies ist die README-Datei des Projekts. Hier sollten Sie Ihr Projekt
|
||||
beschreiben.
|
||||
Erzählen Sie dem Leser (jemand, der nichts über dieses Projekt weiss),
|
||||
alles, was er/sie wissen muss. Üblicherweise sollte der Kommentar
|
||||
zumindest die folgenden Angaben umfassen:
|
||||
------------------------------------------------------------------------
|
||||
|
||||
PROJEKTBEZEICHNUNG:
|
||||
PROJEKTZWECK:
|
||||
VERSION oder DATUM:
|
||||
WIE IST DAS PROJEKT ZU STARTEN:
|
||||
AUTOR(EN):
|
||||
BENUTZERHINWEISE:
|
|
@ -0,0 +1,68 @@
|
|||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse Stack.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class Stack<T>
|
||||
{
|
||||
public Node<T> first;
|
||||
|
||||
public Stack(){
|
||||
}
|
||||
public boolean isEmpty(){
|
||||
if(first == null){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public void push (T neu) {
|
||||
Node<T> n = new Node<T>(neu);//Neue Node mit Zahl "neu " anlegen
|
||||
|
||||
//Überprüfe ob die liste leer ist
|
||||
if(first == null){
|
||||
//setze neue node als erster Eintrag
|
||||
first = n;
|
||||
}
|
||||
else {
|
||||
Node<T> current = first;
|
||||
|
||||
while(current.next != null){
|
||||
current = current.next;
|
||||
}
|
||||
current.setNext(n);
|
||||
}
|
||||
|
||||
//current ist jetzt der letzte Eintrag
|
||||
//setze neue Node als Nachfolger von bisher letztem Eintrag
|
||||
}
|
||||
|
||||
public int laenge(){
|
||||
Node current = first;
|
||||
int laenge = 0;
|
||||
while(current != null){
|
||||
current = current.next;
|
||||
laenge++;
|
||||
}
|
||||
return laenge;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public T pop(){
|
||||
if(first == null){
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
Node<T> current = first;
|
||||
first = first.next;
|
||||
return current.wert;
|
||||
}
|
||||
|
||||
}
|
||||
public T top(){
|
||||
|
||||
return first.wert;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
#BlueJ package file
|
||||
dependency1.from=Menge
|
||||
dependency1.to=Node
|
||||
dependency1.type=UsesDependency
|
||||
dependency2.from=List
|
||||
dependency2.to=Node
|
||||
dependency2.type=UsesDependency
|
||||
dependency3.from=Queue
|
||||
dependency3.to=Node
|
||||
dependency3.type=UsesDependency
|
||||
dependency4.from=LinkedList
|
||||
dependency4.to=Node
|
||||
dependency4.type=UsesDependency
|
||||
dependency5.from=Stack
|
||||
dependency5.to=Node
|
||||
dependency5.type=UsesDependency
|
||||
dependency6.from=test
|
||||
dependency6.to=Node
|
||||
dependency6.type=UsesDependency
|
||||
dependency7.from=test
|
||||
dependency7.to=Queue
|
||||
dependency7.type=UsesDependency
|
||||
editor.fx.0.height=728
|
||||
editor.fx.0.width=800
|
||||
editor.fx.0.x=1060
|
||||
editor.fx.0.y=217
|
||||
objectbench.height=100
|
||||
objectbench.width=776
|
||||
package.divider.horizontal=0.6
|
||||
package.divider.vertical=0.8003731343283582
|
||||
package.editor.height=422
|
||||
package.editor.width=661
|
||||
package.editor.x=289
|
||||
package.editor.y=511
|
||||
package.frame.height=600
|
||||
package.frame.width=800
|
||||
package.numDependencies=7
|
||||
package.numTargets=7
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.height=60
|
||||
readme.name=@README
|
||||
readme.width=48
|
||||
readme.x=10
|
||||
readme.y=10
|
||||
target1.height=70
|
||||
target1.name=test
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.width=120
|
||||
target1.x=220
|
||||
target1.y=260
|
||||
target2.height=70
|
||||
target2.name=Node
|
||||
target2.showInterface=false
|
||||
target2.type=ClassTarget
|
||||
target2.width=120
|
||||
target2.x=70
|
||||
target2.y=10
|
||||
target3.height=70
|
||||
target3.name=Menge
|
||||
target3.showInterface=false
|
||||
target3.type=ClassTarget
|
||||
target3.width=120
|
||||
target3.x=160
|
||||
target3.y=90
|
||||
target4.height=70
|
||||
target4.name=List
|
||||
target4.showInterface=false
|
||||
target4.type=ClassTarget
|
||||
target4.width=120
|
||||
target4.x=160
|
||||
target4.y=170
|
||||
target5.height=70
|
||||
target5.name=Queue
|
||||
target5.showInterface=false
|
||||
target5.type=ClassTarget
|
||||
target5.width=120
|
||||
target5.x=10
|
||||
target5.y=220
|
||||
target6.height=70
|
||||
target6.name=LinkedList
|
||||
target6.showInterface=false
|
||||
target6.type=ClassTarget
|
||||
target6.width=120
|
||||
target6.x=30
|
||||
target6.y=140
|
||||
target7.height=70
|
||||
target7.name=Stack
|
||||
target7.showInterface=false
|
||||
target7.type=ClassTarget
|
||||
target7.width=120
|
||||
target7.x=10
|
||||
target7.y=300
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
/**
|
||||
* Beschreiben Sie hier die Klasse test.
|
||||
*
|
||||
* @author (Ihr Name)
|
||||
* @version (eine Versionsnummer oder ein Datum)
|
||||
*/
|
||||
public class test
|
||||
{
|
||||
public static void test(){
|
||||
Node<String> test = new Node<String>("Hallo");
|
||||
Node<Integer> test2 = new Node<Integer>(5);
|
||||
|
||||
|
||||
Queue<Integer> liste = new Queue<Integer>();
|
||||
/*liste.einfuegen(5);
|
||||
liste.einfuegen(6);
|
||||
liste.einfuegen(8);
|
||||
liste.einfuegen(3);
|
||||
liste.einfuegen(7);
|
||||
liste.einfuegen(9);
|
||||
liste.loesche(2);
|
||||
liste.hinzufügen(4,"wirklich");*/
|
||||
liste.enqueue(7);
|
||||
liste.enqueue(4);
|
||||
liste.enqueue(8);
|
||||
liste.enqueue(2);
|
||||
liste.enqueue(0);
|
||||
liste.enqueue(4);
|
||||
int Selection = liste.dequeue();
|
||||
System.out.println("Die Zahl " +Selection+" wurde entfernt.");
|
||||
int Selection2 = liste.dequeue();
|
||||
System.out.println("Die Zahl " +Selection2+" wurde entfernt.");
|
||||
int Angabe = liste.front();
|
||||
System.out.println("Aktuell ist die erste Zahl " +Angabe+".");
|
||||
Node current = liste.first;
|
||||
|
||||
while(current != null){
|
||||
System.out.println( current.wert );
|
||||
current = current.next;
|
||||
}
|
||||
|
||||
System.out.println("Die Liste hat "+liste.laenge()+" Einträge. ");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue