Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. zadatak
- struct Node
- {
- int data;
- struct Node* next;
- };
- struct Node* createList() {
- int arr[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
- struct Node* p = (struct Node*)malloc(sizeof(struct Node));
- for (int i = 0; i < 10; i++) {
- p->data = arr[i];
- p->next = (struct Node*)malloc(sizeof(struct Node));
- p = p->next;
- }
- p->next = NULL;
- return p;
- }
- void addNode(struct Node* p, int x) {
- while (p->next != NULL) {
- if (x > p->data) {
- struct Node* novi = (struct Node*)malloc(sizeof(struct Node));
- novi->data = x;
- novi->next = p->next;
- p->next = novi;
- return;
- }
- p = p->next;
- }
- struct Node* novi = (struct Node*)malloc(sizeof(struct Node));
- novi->data = x;
- novi->next = NULL;
- p->next = novi;
- }
- // 2. zadatak
- /**/
- // 3. zadatak
- struct cvor {
- int x;
- struct cvor *left, *right;
- };
- int findMin(struct cvor* root)
- {
- if (root == NULL) { return -1; }
- int res = root->x;
- int lres = findMin(root->left);
- int rres = findMin(root->right);
- if (lres < res) { res = lres; }
- if (rres < res) { res = rres; }
- return res;
- }
- int addBT(struct cvor* root)
- {
- if (root == NULL) {
- return 0;
- }
- return (root->key + addBT(root->left) + addBT(root->right));
- }
Advertisement
Add Comment
Please, Sign In to add comment