Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct cvor {
- char x;
- struct cvor *left, *right;
- }BS;
- int pronadi(BS *r, char x) {
- BS *p = r;
- while (p != NULL) {
- if (x > p->x) p = p->right;
- else if (x < p->x) p = p->left;
- else return 1;
- }
- return 0;
- }
- void ubaci(BS *r, char p) {
- BS *novi = (BS *)malloc(sizeof(BS)), *temp = r;
- if (pronadi(r, p)) return;
- novi->x = p;
- novi->left = NULL;
- novi->right = NULL;
- if (r == NULL) r = novi;
- else {
- if ((temp->right == NULL) && (novi->x > temp->x)) temp->right = novi;
- else if ((temp->right != NULL) && (novi->x > temp->x)) temp = temp->right;
- if ((temp->left == NULL) && (novi->x < temp->x)) temp->left = novi;
- else if ((temp->left != NULL) && (novi->x < temp->x)) temp = temp->left;
- }
- }
- int main() {
- return 1;
- }
Advertisement
RAW Paste Data
Copied
Advertisement