Compare commits
	
		
			2 Commits
		
	
	
		
			1ff5ea2a75
			...
			6426a6ccfb
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6426a6ccfb | |||
| a50307c4d4 | 
							
								
								
									
										47
									
								
								uebung03/src/graph/GraphDemo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								uebung03/src/graph/GraphDemo.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
			
		||||
package graph;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class GraphDemo {
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        final Graph graph = makeGraph();
 | 
			
		||||
        System.out.println(graph);
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        final Node nodeA = graph.getNodes().get(0);
 | 
			
		||||
        System.out.println("breadth first: " + nodeList(graph.breadthFirst(nodeA)));
 | 
			
		||||
        System.out.println("depth first: " + nodeList(graph.depthFirst(nodeA)));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Graph makeGraph() {
 | 
			
		||||
        final Node nodeA = new Node("A");
 | 
			
		||||
        final Node nodeB = new Node("B");
 | 
			
		||||
        final Node nodeC = new Node("C");
 | 
			
		||||
        final Node nodeD = new Node("D");
 | 
			
		||||
        final Node nodeE = new Node("E");
 | 
			
		||||
        final Graph graph = new Graph();
 | 
			
		||||
        graph.addNode(nodeA);
 | 
			
		||||
        graph.addNode(nodeB);
 | 
			
		||||
        graph.addNode(nodeC);
 | 
			
		||||
        graph.addNode(nodeD);
 | 
			
		||||
        graph.addNode(nodeE);
 | 
			
		||||
        nodeA.addEdge(new Edge(2, nodeB));
 | 
			
		||||
        nodeA.addEdge(new Edge(4, nodeD));
 | 
			
		||||
        nodeB.addEdge(new Edge(2, nodeA));
 | 
			
		||||
        nodeB.addEdge(new Edge(2, nodeC));
 | 
			
		||||
        nodeB.addEdge(new Edge(4, nodeE));
 | 
			
		||||
        nodeC.addEdge(new Edge(2, nodeB));
 | 
			
		||||
        nodeD.addEdge(new Edge(4, nodeA));
 | 
			
		||||
        nodeD.addEdge(new Edge(2, nodeE));
 | 
			
		||||
        nodeE.addEdge(new Edge(4, nodeB));
 | 
			
		||||
        nodeE.addEdge(new Edge(2, nodeD));
 | 
			
		||||
        return graph;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static String nodeList(ArrayList<Node> nodes) {
 | 
			
		||||
        final ArrayList<String> names = new ArrayList<>();
 | 
			
		||||
        for (Node n : nodes)
 | 
			
		||||
            names.add(n.getName());
 | 
			
		||||
        return names.toString();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -28,6 +28,10 @@ public class Polynomial {
 | 
			
		||||
        this(new int[]{0,1});
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getDegree() {
 | 
			
		||||
        return degree;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Option 1 Kopie des Arrays
 | 
			
		||||
    public int[] getCoeef() {
 | 
			
		||||
        return werte.clone();
 | 
			
		||||
@@ -179,7 +183,7 @@ public class Polynomial {
 | 
			
		||||
    public int apply(int v) {
 | 
			
		||||
        int res = werte[werte.length - 1];
 | 
			
		||||
        for (int i = werte.length - 2; i >= 0; i--)
 | 
			
		||||
            res = res + v * werte[i];
 | 
			
		||||
            res = res * v + werte[i];
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,76 @@
 | 
			
		||||
package polynomial;
 | 
			
		||||
 | 
			
		||||
public class PolynomialDemo {
 | 
			
		||||
    private Polynomial p1 = new Polynomial(new int[]{1,4});
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        //b
 | 
			
		||||
        Polynomial p1 = new Polynomial(new int[]{1, 2, 3, 4});
 | 
			
		||||
        Polynomial p2 = new Polynomial(new int[]{0, 0, 0});
 | 
			
		||||
        Polynomial p3 = new Polynomial(new int[]{3});
 | 
			
		||||
        //Polynomial p99 = new Polynomial(new int[]{});
 | 
			
		||||
 | 
			
		||||
        //c
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        System.out.println(p1.getDegree());
 | 
			
		||||
        System.out.println(p2.getDegree());
 | 
			
		||||
        System.out.println(p3.getDegree());
 | 
			
		||||
 | 
			
		||||
        //f
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        Polynomial p4 = new Polynomial();
 | 
			
		||||
        System.out.println(p4.getDegree());
 | 
			
		||||
 | 
			
		||||
        //g
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        Polynomial p5 = Polynomial.constant(5);
 | 
			
		||||
        System.out.println(p5.getDegree());
 | 
			
		||||
 | 
			
		||||
        //h
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        Polynomial p6 = new Polynomial(new int[]{0, -1, 2, +3, -2, 0, 1});
 | 
			
		||||
        System.out.println(p1);
 | 
			
		||||
        System.out.println(p2);
 | 
			
		||||
        System.out.println(p3);
 | 
			
		||||
        System.out.println(p4);
 | 
			
		||||
        System.out.println(p5);
 | 
			
		||||
        System.out.println(p6);
 | 
			
		||||
 | 
			
		||||
        //i
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        Polynomial p7 = p1.add(p6);
 | 
			
		||||
        System.out.println(p7);
 | 
			
		||||
 | 
			
		||||
        //j
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        Polynomial p8 = p1.sub(p6);
 | 
			
		||||
        Polynomial p9 = p6.sub(p6);
 | 
			
		||||
        Polynomial p10 = p1.mult(p1);
 | 
			
		||||
        Polynomial p11 = p1.mult(p6);
 | 
			
		||||
        System.out.println(p8);
 | 
			
		||||
        System.out.println(p9);
 | 
			
		||||
        System.out.println(p10);
 | 
			
		||||
        System.out.println(p11);
 | 
			
		||||
 | 
			
		||||
        //k
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        Polynomial p12 = p1.add(5);
 | 
			
		||||
        Polynomial p13 = p6.sub(5);
 | 
			
		||||
        Polynomial p14 = p1.mult(5);
 | 
			
		||||
        System.out.println(p12);
 | 
			
		||||
        System.out.println(p13);
 | 
			
		||||
        System.out.println(p14);
 | 
			
		||||
 | 
			
		||||
        //l
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        Polynomial p15 = p1.exp(5);
 | 
			
		||||
        System.out.println(p15);
 | 
			
		||||
        System.out.println(p1.mult(p1).mult(p1).mult(p1).mult(p1));
 | 
			
		||||
 | 
			
		||||
        //m
 | 
			
		||||
        System.out.println();
 | 
			
		||||
        System.out.println(p1.apply(0));
 | 
			
		||||
        System.out.println(p1.apply(1));
 | 
			
		||||
        System.out.println(p1.apply(2));
 | 
			
		||||
        System.out.println(p6.apply(4));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user