Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Mir ist leider ekin passender Name eingefallen, aber der Titel triffts wohl am besten

Ich habe ganz viele Punkte, jeder Punkt kann beliebig(kann auch ne Obergrenze von z.B. 8 sein oder so) viele Verbindungen zu benachbarten Punkten haben.

Fällt einem von euch eine passende Struktur ein um so ein Punktefeld zu speichern?

Ich will jetzt aber nicht so was...

struct Punkt

{

Punkt* p1;

Punkt* p2;

Punkt* p3;

...

}

Sondern was flexibleres...

Hab aber auch keine Lust mit dynamischen Arrays in C/C++ zu hantieren.

Hoffe einer von euch weiß einen "schönen" Ansatz

Danke schonmal

Diablo999

Sowas C-artiges z.B. (naja, der typedef und die Strukturmethode sind glaub schon C++)?

Ich find aber trotzdem Container und Klassenkapselung praktischer.


typedef struct coord

	{

	 int x,y;

	} Coord;


typedef struct Punkt

	{

	 Coord pkt;

// Ohne Obergrenze würde eine (am besten 2-kettig) verlinkte Liste bedeuten

	 Punkt* pktlist[8];

// Strukturmethode zum Initialisieren - kann man auch auslagern

	 void clear() { pkt.x=0; pkt.y=0; for (int i=0; i<8; ++i) pktlist[i]=0; }

	} Pkt;


// sollte man später lieber mit new erzeugen, aber auch wieder weglöschen, deshalb

//lieber jedes erzeugte Pkt-Objekt auch in einer Gesamtliste vermerken.

Pkt* aPkt[3],p1,p2,p3;


// Initialisierung

p1.clear();

p2.clear();

p3.clear();


aPkt[0]=&p1;

aPkt[1]=&p2;

aPkt[2]=&p3;


p1.pkt.x=1;

p1.pkt.y=2;

p1.pktlist[0]=&p2;

p1.pktlist[1]=&p3;


p2.pkt.x=3;

p2.pkt.y=4;

p2.pktlist[0]=&p1;

p2.pktlist[1]=&p3;


p3.pkt.x=5;

p3.pkt.y=6;

p3.pktlist[0]=&p1;

p3.pktlist[1]=&p2;


// nur um zu sehen, wie man was abruft

TRACE("%i %i %i %i\n",p1.pkt.x, p1.pkt.y, aPkt[0]->pktlist[0], aPkt[0]->pktlist[1]);

TRACE("%i %i %i %i\n",p2.pkt.x, p2.pkt.y, aPkt[1]->pktlist[0], aPkt[1]->pktlist[1]);

TRACE("%i %i %i %i\n",p3.pkt.x, p3.pkt.y, aPkt[2]->pktlist[0], aPkt[2]->pktlist[1]);

Hallo,

Originally posted by Crush

Sowas C-artiges z.B. (naja, der typedef und die Strukturmethode sind glaub schon C++)?

Das typedef gibts auch in C, die Methode liesse sich notfalls über einen Funktionspointer realisieren (sofern es C sein muss).

Feste Grenzen sind immer so eine Sache, da die Implementierung nicht besonders flexibel und speicherschonend ist. Entweder du implementierst eine dynamische Speicherverwaltung für das Array oder arbeitest mit verketteten Listen:


struct Punkt {

  int x,y,z;

  struct Punkt *next;

  struct Punkt *prev;

};


Nic

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.