Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct vazel
- {
- string zaglavie;
- string avtor;
- string izdatelstvo;
- struct vazel* rchild;
- struct vazel* lchild;
- } *first = NULL;
- void add(string zagl, string avt, string izd)
- {
- struct vazel* t = root;
- struct vazel* r = NULL, * p;
- if (first == NULL)
- {
- p = new vazel;
- p->zaglavie = zagl;
- p->avtor = avt;
- p->izdatelstvo = izd;
- p->lchild = p->rchild = NULL;
- first = p;
- return;
- }
- while (t != NULL)
- {
- r = t;
- if (avt < t->data)
- t = t->lchild;
- else if (avt > t->data)
- t = t->rchild;
- else
- return;
- }
- p = new vazel;
- p->zaglavie = zagl;
- p->avtor = avt;
- p->izdatelstvo = izd;
- p->lchild = p->rchild = NULL;
- if (avt < r->avtor) r->lchild = p;
- else r->rchild = p;
- }
- int main()
- {
- string zaglavie, avtor, izdatelstvo;
- add(zaglavie, avtor, izdatelstvo);
- }
Add Comment
Please, Sign In to add comment