Autor Beitrag
sebastian1234
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 46



BeitragVerfasst: Mo 24.03.14 19:11 
Nabend,

ich habe mein Programm mittlerweile fast fertig! Es fehlt lediglich noch der Analyse Schritt. Da meine Lösungsansätze bisher nicht so 100% funktioniert haben, bin ich nun auf einen ähnlich Fall im Internet gestoßen. Allerdings in der Sprache Java. Ich kann ja relativ viel in C# umsetzten allerdings fehlen mir bei manchen Dinge die Ansätze wie ich die von Java in C# umschreiben kann. Das sind...

- Was kann ich anstelle von vector verwenden
- Was genau bedeutet double INFINITY = Double.POSITIVE_INFINITY; und was gibt es vergleichbares in C#?

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
public static void main(String[] args) {
   int M = StdIn.readInt();
   int N = StdIn.readInt();
   // read in N vectors of dimension M
   Vector[] vectors = new Vector[N];
   String[] names = new String[N];
   for (int i = 0; i < N; i++) {
        names[i] = StdIn.readString();
        double[] d = new double[M];
        for (int j = 0; j < M; j++)
           d[j] = StdIn.readDouble();
        vectors[i] = new Vector(d);
   }

   double INFINITY = Double.POSITIVE_INFINITY;
   double[][] d = new double[N][N];
   int[] dmin = new int[N];
   for (int i = 0; i < N; i++) {
       for (int j = 0; j < N; j++) {
           if (i == j) d[i][j] = INFINITY;
           else d[i][j] = vectors[i].distanceTo(vectors[j]);
           if (d[i][j] < d[i][dmin[i]]) dmin[i] = j;
       }
   }


Würde mich sehr über Ideen freuen! Vielen Dank!

Moderiert von user profile iconTh69: Codeformatierung überarbeitet.
Yankyy02
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 138
Erhaltene Danke: 21

Win 11 x64
C# (VS 2022 - Rider)
BeitragVerfasst: Mo 24.03.14 21:10 
Hallo Sebastian,

bin zwar kein C# "Guru" und schon gar nicht in Java aber die Vector Klasse in Java ist obsolet und wird durch die Klasse ArrayList weitestgehend ersetzt und ArrayList gibt's auch in C#.
double infinity = Double.POSITIVE_INFINITY ist nichts anderes als die Zuweisung des grösst möglichen double Wertes an infinity. Würde in C# so aussehen:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            double infinity = double.PositiveInfinity;

            Console.WriteLine(infinity); //+unendlich
        }
    }
}


Bitte korrigiert mich wenn ich falsch liege.

MfG

_________________
the quiter you become, the more you are able to hear