Yönsüz graf c++ kodu aciill
-
-
"Yönsüz bir graftaki bütün alt bileşenleri ve düğümlerini tespit eden bir program"
Yazdım.
-
#include <iostream> using namespace std; int main() { cout<<"Yönsüz bir graftaki bütün alt bileşenleri ve düğümlerini tespit eden bir program"; return 0; }
Kod
Yığını: -
Türkçe yazılım makaleleri eksik yetersiz Vikipedi'de dahi graf konusunu anlatıyor, İngilizcesinde konuya ilişkin tutorial linkleri var.
https://tr.wikipedia.org/wiki/Graf_(matematik)
Graf konusunun gerçekte bir cok uygulaması var, öğrenirseniz ilerde işinize de yarayabilir.
Konuya dair tutorial'larda Python ve Java kullanılmış. Onlardan ilgili (çalışan) kodu bulup iletirsen C++'a çevirmede yardımcı olabilirim. -
Bunu istemediğimi bilmiyor olmanız üzdü ve şaşırttı :(
-
Python ve java olan kodunu da bulamadım :(
-
Alt Bileşen Düğümler
1 1,3,5,7,9
2 2,4,10,12,6 …
Örnek olarak Program çıktısı bu şekilde olacak
-
Kodu buldum fakat hatalar var. Yanlarına yazdım bakabilir misiniz?
#include <iostream>
#include <iomanip>
//#include <locale.h> //
using namespace std;
int main (){
int sdizi[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int sycc=1;
bool buluc(int dizi[], int sayi);
sdizi[0]=1;
short graph[20]
[20]={{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},{1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}};
for (int i=0 ; i<20 ; i++)
{
for (int j=0 ; j<20 ; j++)
{
if(graph[i][j]!= 0)
{
if(buluc(sdizi,j+1))
sdizi[sycc]=j+1; sycc++;}
}
}
}
//setlocale(LC_ALL, "Turkish");
cout << endl << "alt_bilesen" << setw(10) << "dugumler" < endl << endl; (burada hata alıyorum coutta)
cout << setw(6) << 1 << setw(4) << " "; (burada hata alıyorum coutta)
for(int m=0 ; m<20 ; m++) (for da ve m lerde hata alıyorum)
{
if(sdizi[m]>0 && sdizi[m]<21) cout << setw(4) << sdizi[m];}
return 0 ; (burada hata alıyorum)
} (bide burada hata)
bool buluc(int dizi[], int sayi){
for(int i=0 ; i<20 ; i++){
if(dizi[i] == sayi) return false;}
return true;
}
-
#include <iostream> #include <iomanip> using namespace std; int main() { int sdizi[20] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; int sycc = 1; bool buluc(int dizi[], int sayi); sdizi[0] = 1; short graph[20][20] = { {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1}, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0} }; for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { if (graph[i][j] != 0) { if (buluc(sdizi, j + 1)) { sdizi[sycc] = j + 1; sycc++; } } } } cout << endl << "alt_bilesen" << setw(10) << "dugumler" << endl << endl; cout << setw(6) << 1 << setw(4) << " "; for (int m = 0; m < 20; m++) { if (sdizi[m] > 0 && sdizi[m] < 21) cout << setw(4) << sdizi[m]; } return 0; } bool buluc(int dizi[], int sayi) { for (int i = 0; i < 20; i++) { if (dizi[i] == sayi) return false; } return true; }
Kod
Yığını:@Mh97
Kodu formatlayip calisir hale getirdim. Fakat ne istediginiz hala net degil gozumde.
-
Çok teşekkür ederim.
https://forum.donanimhaber.com/grafta-dijkstra-algoritmasi-yardimci-olur-musunuz-lutfen--146370175#146375804 şuraya da bakabilir misiniz rica etsem?
Bu mesaj IP'si ile atılan mesajları ara Bu kullanıcının son IP'si ile atılan mesajları ara Bu mesaj IP'si ile kullanıcı ara Bu kullanıcının son IP'si ile kullanıcı ara
KAPAT X