الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مقارنه عناصر مصفوفه ثنائيه ونقل النتيجه الى مصفوفه احاديه البعد

بدأه samo20 في 7 مارس 2011 · 4 رد · 793 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

انا لدي كود عباره عن graph وقمت بتخزين المعلومات ع شكل adj.matrix اريد حساب عدد الجيران لكل نود

ودلك بااختبار المصفوفه الثنائيه. اي انني اريد القيام بااختبار المصفوفه صف صف وتخزين النتيجه في مصفوفه احاديه لكل صف

من المصفوفه الثنائيه. قمت بعمل دلك عن طريق اللوب استخدمت for and while and i used nested for loops ولكن كلا الطريقتين لم تنجح

هل يوجد لديكم فكره عن طريقه اهتبار المصفوفه صف صف تم تخزين النتجيه في مصفوفه اخرى ز ارجو المساعده

#2

هلا عرضت الكود الذى كتبته حتى نستطيع مساعدتك

تحياتى


﴿وَمَا كَانَ اللَّهُ لِيُعَذِّبَهُمْ وَأَنْتَ فِيهِمْ ۚ وَمَا كَانَ اللَّهُ مُعَذِّبَهُمْ وَهُمْ يَسْتَغْفِرُونَ﴾

الأنفال ۳۳                                  
 

#3

this the code i was trying to compare and compute the value of neighbors node

for each node in the graph

void capac(float graph[max_n][max_n])

{

float cap,m=4; //"m" will define the size of the group which can have values from 0 to n.

// to have small group of trusted nodes the value of m gonna be small and so on.

float seed_cap;

int counter=0,neighbors; // the number of nodes that connected to seed node

int capSeed[max_n]={0};

int* seed;

int j=0,i;

for( i=0;i<n;i++)

{

/*for (int j=0;j<n;j++)

{

if(graph[j]==weight)

counter++;

}

neighbors=counter;

capSeed=neighbors;*/

while(j< n)

{

if (graph[j]==weight) // here is the problem, not counting.

counter++;

cout<<counter;

neighbors=counter;

capSeed=neighbors; // store the number of neighbor nodes for each node in the graph,

j++; // which can be used to compute the capacity for seed node.

}

}

for(int k=0;k<n;k++)

cout<<capSeed[k]<<" ";

// for(int k=0;k<n;k++)

// {

// if (capSeed[k]==weight)

// neighbors=counter++;

// }

// cout<<"enter a value to identify the size of group that you want to be trusted";

//cin>>m;

int d;

d=pow(2,m); // calculate the seed's capacity.

for(int z=0,z<n,z++)

seed_cap[z]=d*neighbors;

cout<< "the capacity of each node in the graph as a seed nod is "<<seed_cap[z];

}

i was trying to use different methods but I don't know where is the problem

Do I need to use pointer?

Thx?

#4

السلام عليكم ورحمة الله

لم أفهم المشكلة بالقدر الكافي ولكن بحسب ما فهمت ...

1- هل تأكدت من قيمة weight ؟

2- عليك تصفير قيمة المتحول counter عند كل انتقالة في المصفوفة الثنائية من صف إلى آخر كالتالي مثلا :

for( i=0;i<n;i++)
{

counter = 0;

while(j< n)

{

if (graph[j]==weight) // here is the problem, not counting.

counter++;

cout<<counter;

neighbors=counter;

capSeed=neighbors; // store the number of neighbor nodes for each node in the graph,

j++; // which can be used to compute the capacity for seed node.

}

}

جرب ذلك , إن كانت المشكلة غير ذلك يرجى التوضيح أكثر

بتوفيق الله..

تم تعديل هذه المشاركة بواسطة MoHaMMaD Pro في 8 مارس 2011 في 05:24

1

Everything will be fine when we TALK LESS, DO MORE


#5

شكرا جزيلا لتنبيهي لتصفير قيمه counter

المشكله الاساسيه انه لاتتم عمليه المقارنه وقيمه الكونتر تبقى كماهي صفر. وبدلك تكون قيم المصفوفه capSeed ايضا اصفار.

علما بان المصفوفه graph[max_n][max_n]

تم تعريفها كمتغير عام

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…