opcenito stablo - implementacija


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #ifndef OSTABLO_H_
  2. #define OSTABLO_H_
  3.  
  4. typedef int node;
  5.  
  6. struct elem {
  7. char label[MAX_DULJINA];
  8. node firstchild, nextsibling;
  9. };
  10. struct tr {
  11. struct elem elements[1000];
  12. node first;
  13. };
  14. typedef struct tr tree;
  15.  
  16. tree *InitT(char *x,tree *T){
  17. T = new tree[MAX_VELICINA_POLJA];
  18. T->first=0;
  19. T->elements[0].firstchild=IZLAZ;
  20. T->elements[0].nextsibling=IZLAZ;
  21. strcpy(T->elements[0].label,x);
  22. return T;
  23. }
  24. node RootT(tree *T){
  25. return T->first;
  26. }
  27. node NextSiblingT(node n,tree *T){
  28. return T->elements[n].nextsibling;
  29. }
  30. node FirstChildT(node n,tree *T){
  31. return T->elements[n].firstchild;
  32. }
  33. bool CreateT(char *x,node n,tree *T){
  34. static int uk_broj=1;
  35. if(uk_broj>=MAX_VELICINA_POLJA) return 1;
  36. if(T->elements[n].firstchild == IZLAZ){
  37. T->elements[n].firstchild = uk_broj;
  38. strcpy(T->elements[uk_broj].label,x);
  39. T->elements[uk_broj].firstchild = IZLAZ;
  40. T->elements[uk_broj].nextsibling = IZLAZ;
  41. }
  42. else{
  43. node cvor=FirstChildT(n,T);
  44. while(NextSiblingT(cvor,T)!=IZLAZ) cvor = NextSiblingT(cvor,T);
  45. T->elements[cvor].nextsibling = uk_broj;
  46. strcpy(T->elements[uk_broj].label,x);
  47. T->elements[uk_broj].firstchild = IZLAZ;
  48. T->elements[uk_broj].nextsibling = IZLAZ;
  49. }
  50. uk_broj++;
  51. return 0;
  52. }
  53. char *LabelT(node n,tree *T){
  54. return T->elements[n].label;
  55. }
  56. void ChangeLabelT(char *x,node n,tree *T){
  57. strcpy(T->elements[n].label,x);
  58. }
  59. void DeleteT(node n,tree *T){
  60. node cvor = FirstChildT(n,T);
  61. T->elements[n].firstchild=IZLAZ;
  62. while(cvor!=IZLAZ){
  63. DeleteT(cvor,T);
  64. cvor=NextSiblingT(cvor,T);
  65. }
  66. if(T->first==n){
  67. return;
  68. }
  69. else
  70. for (int i=0;i<MAX_DULJINA;i++){
  71. if(T->elements[i].firstchild==n) {
  72. node a = T->elements[i].firstchild;
  73.  
  74. }
  75. }
  76. }
  77. #endif

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.