inplementacija pomocu polja i pokazivaca





0
Date Submitted Mon. Jan. 11th, 2010 7:17 AM
Revision 1 of 1
Beginner mbelsak
Tags bina
Comments 0 comments
Primijetio sam da su neke od kolega koristili rekurzivne funkcije kod DeleteT, zatim primijeto sam da su neki koristili funkciju malloc kod inicijalizacije , ja sam napravio InitT bez toga, za razliku od mene koristili su pokazivace na formalne varijable funkcije.

<#include<iostream>
struct element {
       int vrijednost;
       int postoji;
               };
               
struct bt {
        element elementi[10000];
           };
           
bt btree;
int cvor;


int ParentT(cvor n, btree tree) {
       if(n==1)
           return (-1);
       else
           return (int(n/2));
                                 }


int FirstChildT(cvor n, btree tree) {
         if(tree[2*n].postoji>n)
            return (-1);
         else
            return 2*n;
                                     }

int NextSiblingT(cvor n, btree *tree) {
    if(tree.[2*n+1].postoji>n)
                return (-1);
         else
             return 2*n+1;
                                      }


int LabelT(cvor n,btree *tree) {
    if(tree[n].postoji == 0)
       return (-1);
    else
       return tree[n].vrijednost,
                               }

int RootT(btree tree) {
     return tree[1].vijednost;
                      }

void CreateT(int x, cvor n, btree tree) {
     if(!tree[2*n].postoji)
          tree[n*2]=x;
     else
          tree[n*2+1]=x;
                                        }

void ChangeLabel(int x, cvor n, btree tree) {
        if(tree[n].postoji)
            tree[n].vrijednost=x,
        else
           return (-1);
                                            }

void DeleteT(cvor n, btree tree) {
     int l=0;
     while(tree[n*2].postoji)
          tree[n*2]=NULL;
     while(tree[n*2+1].postoji)
          tree[n*2+1]=NULL;
     while(tree[int(n/2)].postoji)
          tree[int(n/2)].postoji=NULL;
                                 }


void InitT(int x,btree tree ) {
     
     for(int i=0;i<10000;i++) {
            tree[i].postoji=NULL;
            tree[i].vrijednost=NULL;
                              }
     
                              }



/////////Pomocu pokazivaca///////////
#include<iostream>
struct tcvor {
   int vrijednost;
   tcvor *lchild,*rchild;
             };
tcvor cvor;
tcvor btree;


int Parent(cvor n, btree tree) {
    int provjera =0;
    node polje[10000];
    int node;
    while(!provjera) {
                if (c->lchild != n) && (c.rchild != n)) {
                        if (c->lchild != NULL)
                                polje[c]=c->lchild;
                        if (i->desni != NULL)
                                polje[c]=i->rchild;
                c++;
                }
                else provjera = 1;
                }
        if(provjera)
                return(polje[c]);
        else
                return 0;
                               }

int FirstChildT(cvor n, btree tree) {
    return n->lchild;
                                    }

int NextSiblingT(cvor n, btree tree) {
    return n->rchild;
                                     }

int LabelT(cvor n, btree tree) {
    return n->vrijednost;
                               }

int RootT(btree tree) {
    return tree;
                      }

void CreateT(int x, cvor n, btree tree) {
     if(n->lchild == 0)
          n->lchild=x;
     if(n->lchild!=0)
          n->rchild=x;
                                        }

void ChangeLabelT(int x, cvor n, btree tree) {
     n->vrijednost=x;
                                             }

void DeleteT(cvor n, btree tree) {
     while(n->lchild)
           n->lchild=NULL;
     while(n->rchild)                      }
           n->rchild=NULL;
     while(n->vrijednost)
           n->vrijednost=NULL;

void InitT(int x, btree tree) {
     node n;
     n->lchild=NULL;
     n->rchild=NULL;
     n->vrijednost=x;
                               }
 

aaa bbb

Comments

There are currently no comments for this snippet.

Voting

Votes Up


Votes Down