Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- typedef unsigned char itemType;
- typedef char* infoType;
- const char itemMIN = char(0);
- char infoNIL[] = "Z-noden";
- const int MAX = 29312;
- struct node {
- itemType key;
- int ant_f;
- node *l, *r, *t;
- node(itemType k, node* ll, node* rr, node* tt)
- { key = k; l = ll; r = rr; t = tt; ant_f=1; }
- };
- node *z;
- struct node insert(itemType v,int lvl,struct node * tre) {
- struct node *p,*x;
- p = tre;
- x = p->r;
- while (x != z) {
- p = x;
- if (x->key == v){
- if(lvl == 2){
- x->ant_f++;
- cout << "\nteller opp " << x->key << '\n';
- cout << x->ant_f;
- }
- return *x;
- }
- x = (v<x->key) ? x->l : x->r;
- }
- cout << "\nInserter node "<<v<<" i tre: " << lvl<<endl;
- x = new node(v,z,z,z);
- x->t = new node(NULL,z,z,z);
- if (v<p->key)
- p->l = x;
- else
- p->r = x;
- return *x;
- }
- int main() {
- node *head,*tmp;
- z = new node(NULL, z, z, z);
- head = new node(NULL, z, z,z);
- tmp = new node(NULL, z, z,z);
- ifstream infile("OPPG_17.txt");
- char nr;
- while(!infile.eof()) {
- infile >> nr;
- *tmp = insert(nr,1,head);
- infile >> nr;
- insert(nr,2,tmp->t);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement