التنبيهات التالية ظهرت :
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 864 - File: showthread.php PHP 7.4.33 (Linux)
File Line Function
/showthread.php 864 errorHandler->error



تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مساعده في حل برنامج الشجرة بلغة c++6.0
#1
سلام عليكم ورحمة الله وبركاته

كيف حال ان شاء الله بخير صحة وعافية

اريد اضيف شرط في دالة طباعة inorder في برنامج الشجرة 

void inorder(nodeptr & t)
{
if(t!=NULL)
{
inorder(t->l);
cout<<t->info<<"---";
inorder(t->r);
}
}

الشرط هو اذا ضفت عقدة وسطية للشجرة من اضغط رقم 4 inorder مايطبع برنامج يعني اذا دخلت شجرة متعددة مايطبع inorder بس اذا دخلت شجرة ثنائية يطبع inorder فما هو شرط الذي استخدمه بالدالة

وهذا برنامج كامل

#include<iostream.h>
#include<stdlib.h>
#define null 0;
struct node
{
char info;
struct node *l,*m,*r;
};
typedef struct node *nodeptr;

void creatnode(nodeptr &t)
{
char ch;
if(t==NULL)
{
t=new node;
cout<<"enter value into tree node =";
cin>>t->info;
t->l=null;
t->m=null;
t->r=null;
cout<<"do you want add node form left="<<t->info<<endl;
cout<<"choose(y)or(n)=";
cin>>ch;
if(ch=='y')
creatnode(t->l);
cout<<"do you want add node form middle"<<t->info<<endl;
cout<<"choose(y)or(n)=";
cin>>ch;
if(ch=='y')
creatnode(t->m);
cout<<"do you want add node form right="<<t->info<<endl;
cout<<"choose(y)or(n)=";
cin>>ch;
if(ch=='y')
creatnode(t->r);
}
}
void preorder(nodeptr &t)
{
if(t!=NULL)
{
cout<<t->info<<"---";
preorder(t->l);
preorder(t->m);
preorder(t->r);
}
}
void postorder(nodeptr &t)
{
if(t!=NULL)
{
postorder(t->l);
postorder(t->m);
postorder(t->r);
cout<<t->info<<"---";
}
}
void inorder(nodeptr & t)
{
if(t!=NULL)
{
inorder(t->l);
cout<<t->info<<"---";
inorder(t->r);
}
}
void main()
{
int x;
nodeptr t;
t=null;
do
{
cout<<"1-creatnode\n";
cout<<"2-preorder\n";
cout<<"3-postorder\n";
cout<<"4-inorder\n";
cout<<"5-exit\n";
cout<<"enter your choice?";
cin>>x;
switch(x)
{
case 1:creatnode(t);break;
case 2:preorder(t);break;
case 3:postorder(t);break;
case 4:inorder(t);break;
default:break;
}
}
while(x!=5);
}

الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
مساعده في حل برنامج الشجرة بلغة c++6.0 - بواسطة PG_MJM - 11-03-23, 08:55 PM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم