diff --git a/Programmierung2/src/DesignPatterns/.~lock.All Design Patterns.odt# b/Programmierung2/src/DesignPatterns/.~lock.All Design Patterns.odt# new file mode 100644 index 0000000..9a3cd25 --- /dev/null +++ b/Programmierung2/src/DesignPatterns/.~lock.All Design Patterns.odt# @@ -0,0 +1 @@ +,OBAI/obaya,obai,21.09.2024 22:26,file:///C:/Users/obaya/AppData/Roaming/LibreOffice/4; \ No newline at end of file diff --git a/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/JTest.java b/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/JTest.java new file mode 100644 index 0000000..dfab4c8 --- /dev/null +++ b/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/JTest.java @@ -0,0 +1,63 @@ +package QueueStructure.CircularQueue_UsingArray; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import QueueStructure.MyQueue; + +class JTest { + MyCircularQueue test; + + @BeforeEach + void erstelle_List() { + test = new MyCircularQueue<>(6); + } + + @Test + void test_Enqueue() throws MyException { + + assertEquals(1,test.enqeueu(1)); + } + + @Test + void test_getFront() throws MyException { + test.enqeueu(4); + test.enqeueu(2); + test.enqeueu(6); + assertEquals(4,test.getFront()); + } + + @Test + void test_getRear() throws MyException { + test.enqeueu(4); + test.enqeueu(2); + test.enqeueu(6); + assertEquals(6,test.getRear()); + } + + @Test + void test_dequeue() throws MyException { + test.enqeueu(4); + test.enqeueu(2); + test.enqeueu(6); + assertTrue(test.dequeue()); + } + + @Test + void test_clear() throws MyException { + test.enqeueu(4); + test.enqeueu(2); + test.enqeueu(6); + assertTrue(test.clear()); + } + + @Test + void test_getSize() throws MyException { + + test.enqeueu(6); + assertEquals(1,test.getsize()); + } +} diff --git a/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/MyCircularQueue.java b/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/MyCircularQueue.java new file mode 100644 index 0000000..ca3864c --- /dev/null +++ b/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/MyCircularQueue.java @@ -0,0 +1,83 @@ +package QueueStructure.CircularQueue_UsingArray; + +public class MyCircularQueue { + + private T wert; + private T arr[]; + private int erst;// oder (Head, first, begin) + private int last; // oder (back,last,tail,end) + private int size; + + private int zaeler = 0; // checke für die länge meiner Queue + + MyCircularQueue(int size) { + this.size = size; + arr =(T[]) new Object[size]; + initi_werte(); + } + + public void initi_werte() { + erst = -1; + last = -1; + } + + public T enqeueu(T value) throws MyException{ + + this.wert = value; + if(isEmpty()) + erst++; + + zaeler++; + last = (last + 1) % size; + arr[last] = value; + + return arr[last]; + } + + public boolean dequeue() { + if(isEmpty()) + return false; + + zaeler--; + erst = (erst + 1) % size; + erst++; + return true; + } + + public T getFront()throws MyException { + if(isEmpty()) + throw new MyException("Queue ist leer"); + + return arr[erst]; + } + + public T getRear()throws MyException { + if(isEmpty()) + throw new MyException("Queue ist leer"); + + return arr[last]; + } + + public boolean isFull() { + return last >= arr.length - 1; + } + + public boolean isEmpty() { + return erst == -1 && last == -1; + } + + public boolean clear() { + if (!isEmpty()) { + initi_werte(); + return true; + } + return false; + } + + public int getsize() { + if (isEmpty()) + return -1; + + return zaeler; + } +} diff --git a/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/MyException.java b/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/MyException.java new file mode 100644 index 0000000..4031c98 --- /dev/null +++ b/Programmierung2/src/QueueStructure/CircularQueue_UsingArray/MyException.java @@ -0,0 +1,9 @@ +package QueueStructure.CircularQueue_UsingArray; + +public class MyException extends Exception { + + MyException(String fheler){ + super(fheler); + } + +} diff --git a/Programmierung2/src/QueueStructure/JTest.java b/Programmierung2/src/QueueStructure/JTest.java new file mode 100644 index 0000000..8dd52f5 --- /dev/null +++ b/Programmierung2/src/QueueStructure/JTest.java @@ -0,0 +1,43 @@ +package QueueStructure; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +class JTest { + + MyQueue test; + + @BeforeEach + void erstelle_List() { + test = new MyQueue(5); + } + + @Test + public void test_Enqueue() throws MyException { + + + assertEquals(10,test.enqueue(10)); + assertEquals(120,test.enqueue(120)); + } + + @Test + public void test_isfull() throws MyException { + test.enqueue(10); + test.enqueue(10); + test.enqueue(10); + test.enqueue(10); + test.enqueue(10); + assertTrue(test.isFull()); + + } + + @Test + public void test_isempty() throws MyException { + + assertTrue(test.isEmpty()); + + } + +} diff --git a/Programmierung2/src/QueueStructure/Main.java b/Programmierung2/src/QueueStructure/Main.java new file mode 100644 index 0000000..a615fb9 --- /dev/null +++ b/Programmierung2/src/QueueStructure/Main.java @@ -0,0 +1,20 @@ +package QueueStructure; + +public class Main { + + public static void main(String[] args) throws MyException { + MyQueue test = new MyQueue(5); + try { + test.enqueue(10); + test.enqueue(120); + test.enqueue(140); + test.enqueue(140); + test.enqueue(140); + + test.printAll(); + } catch (MyException e) { + System.out.println(e.toString() + e.getClass()); + } + System.out.println(3 % 5); + } +} diff --git a/Programmierung2/src/QueueStructure/MyException.java b/Programmierung2/src/QueueStructure/MyException.java new file mode 100644 index 0000000..daac660 --- /dev/null +++ b/Programmierung2/src/QueueStructure/MyException.java @@ -0,0 +1,9 @@ +package QueueStructure; + +public class MyException extends Exception { + + MyException(String fheler){ + super(fheler); + } + +} diff --git a/Programmierung2/src/QueueStructure/MyQueue.java b/Programmierung2/src/QueueStructure/MyQueue.java new file mode 100644 index 0000000..b077876 --- /dev/null +++ b/Programmierung2/src/QueueStructure/MyQueue.java @@ -0,0 +1,69 @@ +package QueueStructure; + +public class MyQueue { + int wert; + int erst; + int last; + int arr[]; + + MyQueue(int size) { + arr = new int[size]; + erst = -1; + last = -1; + } + + public int enqueue(int value) throws MyException { + if (isFull()) + throw new MyException ("Kein Platz mehr in der Queue"); + this.wert = value; + + if (erst == -1) + erst++; + + last++; + arr[last] = wert; + return arr[last]; + + } + + + public void deqeue() throws MyException { + if (isEmpty()) + throw new MyException ("Queue ist leer!"); + + if (erst == last) { + erst = -1; + last = -1; + return; + } + erst++; + + } + + public int peek() throws MyException { + if (isEmpty()) + throw new MyException ("Queue ist leer!"); + + return arr[erst]; + } + + public boolean isEmpty() { + return last == -1 && erst == -1; + } + + public boolean isFull() { + return last >= arr.length-1; + } + + + public void printAll() throws MyException { + if (isEmpty()) + throw new MyException ("Queue ist leer!"); + System.out.print("["); + for (int i = erst; i < last; i++) + System.out.print(arr[i] + " "); + + System.out.print("]"); + } + +}