Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. typedef unsigned char itemType;
  6. typedef char* infoType;
  7.  
  8.  
  9. const char itemMIN = char(0);
  10. char infoNIL[] = "Z-noden";
  11. const int MAX = 29312;
  12.  
  13.  
  14.  
  15. struct node {
  16. itemType key;
  17.  
  18. int ant_f;
  19.  
  20. node *l, *r, *t;
  21.  
  22. node(itemType k, node* ll, node* rr, node* tt)
  23. { key = k; l = ll; r = rr; t = tt; ant_f=1; }
  24. };
  25.  
  26.  
  27.  
  28. node *z;
  29.  
  30.  
  31. struct node insert(itemType v,int lvl,struct node * tre) {
  32.  
  33. struct node *p,*x;
  34. p = tre;
  35. x = p->r;
  36.  
  37. while (x != z) {
  38. p = x;
  39. if (x->key == v){
  40. if(lvl == 2){
  41. x->ant_f++;
  42. cout << "\nteller opp " << x->key << '\n';
  43. cout << x->ant_f;
  44. }
  45. return *x;
  46. }
  47. x = (v<x->key) ? x->l : x->r;
  48. }
  49. cout << "\nInserter node "<<v<<" i tre: " << lvl<<endl;
  50. x = new node(v,z,z,z);
  51. x->t = new node(NULL,z,z,z);
  52. if (v<p->key)
  53. p->l = x;
  54. else
  55. p->r = x;
  56.  
  57. return *x;
  58. }
  59.  
  60. int main() {
  61.  
  62. node *head,*tmp;
  63.  
  64. z = new node(NULL, z, z, z);
  65. head = new node(NULL, z, z,z);
  66. tmp = new node(NULL, z, z,z);
  67.  
  68. ifstream infile("OPPG_17.txt");
  69. char nr;
  70. while(!infile.eof()) {
  71. infile >> nr;
  72. *tmp = insert(nr,1,head);
  73. infile >> nr;
  74. insert(nr,2,tmp->t);
  75. }
  76.  
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement