A Ternary Tree (T) is a tree in which every non terminal node has at most 3 children.
We will use T to simulate the following activity:
A set of P candidates must pass a set of exams ordered in an array of N exam codes (an exam code is an array of char). For a given exam, a candidate can be in one of the 3 following cases: success, failure or non-passed exam yet. Thus, every T node represents an exam with: exam code as root, succeeded candidates as left child, failed candidates as right child and in the middle whose didn’t pass exam yet. The following figure depicts 2 exams and the situation of 10 candidates: how to write it :)

how to write it :)

Is this your question? If so, you'll need to put forth a little bit of effort. I doubt anyone is willing to write a ternary tree for you because you're too lazy to make an attempt.

i'm so sorry for this answer but if i don't need ur help i wouldn't sign up here to contact with u!!!!!! i'm a student and i'm not good in this course this data structure i repeat it many times ,, i need to graduate only for my parents ,, i'll not going to work in this domain because i don't like it but i need to graduated ,,, i wrote something in this program, but this is my first time to put my question here because of this i didn't write anything more ,, but if u can't help me u can say sorry we can't help u and don't write some silly words because when i wrote to u i wrote in a respect way ,,,,

you need to read about it, what it is and then construct it

look i wrote BT add(BT T,BTe1,BT T1){.......... i wrote some things in this program and sorry for asking u now i'll delete my account thx a lot.

i'm so sorry for this answer but if i don't need ur help i wouldn't sign up here to contact with u!!!!!! i'm a student and i'm not good in this course this data structure i repeat it many times ,, i need to graduate only for my parents ,, i'll not going to work in this domain because i don't like it but i need to graduated ,,, i wrote something in this program, but this is my first time to put my question here because of this i didn't write anything more ,, but if u can't help me u can say sorry we can't help u and don't write some silly words because when i wrote to u i wrote in a respect way ,,,,

Please read our rules: "Do provide evidence of having done some work yourself if posting questions from school or work assignments". If you aren't willing to do anything, we'll show exactly the same attitude toward helping you. I'm happy to teach what I know about ternary trees, but not to a time vampire who has no interest in putting forth even enough effort to pass his class.

So I'll kindly suggest once more that you show some proof of effort, or I'll close this thread as it's in violation of our homework rule.

typedef struct {
               int T[P];
                int size ;
}Array_ID;
typedef union{
    char ExamCode[10];
    Array_ID candidates;
}element;
typedef struct node{
    element data;
    struct node *left,*middle,*right;
}*T;
//void init(T tree,char* A[],int dim){
//  int i=1;
//  tree=(node*)malloc(sizeof(node));
//  if(i==dim){
//      tree->data = A[dim-1];
//      tree->left = tree->middle= tree->right = NULL;
//  }
//
void init(T tree,char* A[],int dim,int i){
    tree = (node*)malloc(sizeof(node));
    if(dim ==1)
        strcpy(tree->data.ExamCode,A[0]);
    else{
        strcpy(tree->data.ExamCode,A[i]);
        tree->left = (node*)malloc(sizeof(node));
        tree->middle = (node*)malloc(sizeof(node));
        tree->right = (node*)malloc(sizeof(node));
        strcpy(tree->left->data.ExamCode,A[i+1]);
        strcpy(tree->right->data.ExamCode,A[i+1]);
        strcpy(tree->middle->data.ExamCode,A[i+1]);
    }
          if(i<dim)
          { i++;
             init(tree->left,A,dim,i);
             init(tree->right,A,dim,i);
             init(tree->middle,A,dim,i);
           }
}
int Belong(T tree,int ID){
    if(tree == NULL)
        return 0;




     typedef struct {
           int T[P];
            int size ;
    }Array_ID;
typedef union{
        char ExamCode[10];
    Array_ID candidates;
}element;
typedef struct node{
    element data;
    struct node *left,*middle,*right;
}*T;
//void init(T tree,char* A[],int dim){
//  int i=1;
//  tree=(node*)malloc(sizeof(node));
    //  if(i==dim){
//      tree->data = A[dim-1];
//      tree->left = tree->middle= tree->right = NULL;
//  }
//
void init(T tree,char* A[],int dim,int i){
    tree = (node*)malloc(sizeof(node));
    if(dim ==1)
        strcpy(tree->data.ExamCode,A[0]);
    else{
        strcpy(tree->data.ExamCode,A[i]);
        tree->left = (node*)malloc(sizeof(node));
        tree->middle = (node*)malloc(sizeof(node));
        tree->right = (node*)malloc(sizeof(node));
        strcpy(tree->left->data.ExamCode,A[i+1]);
        strcpy(tree->right->data.ExamCode,A[i+1]);
        strcpy(tree->middle->data.ExamCode,A[i+1]);
    }
      if(i<dim)
      { i++;
         init(tree->left,A,dim,i);
         init(tree->right,A,dim,i);
         init(tree->middle,A,dim,i);
       }
}
int Belong(T tree,int ID){
    if(tree == NULL)
        return 0;

I'm happy to teach what I know about

i have the whole right code for this program
Init()
Belong(..)
Pass(..)
succeed_List(...)
main()

do you need it ???

i have the whole right code for this program

We don't do homework for people here. This is not a cheat site.

We don't do homework for people here. This is not a cheat site.

maybe it doesent matter if this guy who cheats cant explayn what he did or cheated

Dears,

Why you guys are talking to me in that way ??? am not a cheater, am giving some help for some students who needs this help. If you have any problem in my membership on this site please tell me.
Anyway .. the code that i could provide regarding Ternary Tree still needs some refactoring and they must do some effort to result for a complete successfull project.
You guys should be more friendly .. if some one needs help, lets help him in a way we teach him how to think, without using the words "lazy, vampire, violation .. etc ".

Best Regards,
Bakabozza

i have the whole right code for this program

do you need it ???

is not an offer of help. It's an offer to cheat.

We have no problem with your membership. We simply give guidance, not working code, when we answer questions. This way the student learns and corrects the program himself.

Ok well, i'll provide the students with some CODE regarding this project.
They can learn and still there is a lot of work they should do.
And am sorry but "THIS IS NOT CHEATING". I CANNOT accept this word to be said for ME.
Am a software engineer with experience more than 3 years in one of the most important companies of the middle east, beside that am a trainer. Providing code for the trainee is not a cheating.
For students: Am making some technical updates for the code and i'll provide you with this code once finished (maybe today).
Thanks.

The Init function should construct a tree.
it should takes two arguments: Init(T tree, char * examCode)
if the parent node is null, then it should construct it, else it should add a new examCode to the tree.
IMPLEMENTATION:

void Init(T tree, char * examCode) 
{
    int i;
    T curr;
// if the parent node is null
    if(!tree) 
    {
        curr = (T)malloc(sizeof(T));
        curr->Left = curr->Right = curr->Middle = NULL;
        curr->Data.Candidates.Size = 0;
        for(i=0;i<10;i++)
            curr->Data.ExamCode[i]=0;
        strcpy(curr->Data.ExamCode, examCode);

        tree = curr;
    }
    // else add the new examCode
    else
    {
        Init(tree->Left, examCode);

        Init(tree->Middle, examCode);

        Init(tree->Right, examCode);
   }
}

And am sorry but "THIS IS NOT CHEATING".

It is if we say it is...
As a moderator of these boards with over 10000 posts I know the definition better than you, with your total of 3 posts.

I CANNOT accept this word to be said for ME.

Then don't post working code as an answer to a question and you will not be a cheater. Give guidance instead. This is all I'm saying. Don't post working answers.

Am a software engineer with experience more than 3 years in one of the most important companies of the middle east

So? I'm a software engineer with over 30 years experience with top companies in the US. What of it? I've also trained and taught courses. I also play Backgammon and Go. So there... ;o)

You are so FUNNY man really so FUNNY.
maybe this experience didn't tought you how to comunicate with people.
i don't care about "posts " !!!!!!! no bady cares clone.
so kindly raise your level in talking and DON't act like kids.

Don't post working answers.

No worries, bakabozza didn't post a working answer. There are a number of problems with the posted Init() function such that it's completely unusable without fixing some fundamental errors. And this is excluding the required addition of scaffolding to make it compile.

commented: True, but he DID offer working code -- which is cheating. +0

please mr. bakabozza would you give me the code of other functions please

commented: All this talk about cheating meant nothing to you, obviously... -3

Untitled77

This post has no text-based content.

i want from bakabozza .....the code for the ternary tree( belong,init,pass,succeed_list,main)..thx for your help

I cannot do your work guys, i can give you any help regarding this project but not posting all the related code for these functions. Every one should write his own code.
Try to, and if you need any help you can write down your case and i'll support you.
Lebanese University students should not ask for a Code, It's one of the most stongest universities in the world and you should reflect this here. Every one can ask for help BUT not asking me to do your work.
Thanks;

i wrote the code for all the functions except pass it is not working, plz would u help me with this function only?

yes sure .. send me an email on ahmedeh@netways.com plz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.