Advertisement
Misipuk

BackUp_C

Apr 4th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.74 KB | None | 0 0
  1. #include "ads_tree_pure_c.h"
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. #define N 10
  8. #define R 60
  9.  
  10. int main(){
  11.     int nTask=0;
  12.     int lmax=0, kmax=0;
  13.     int klvl=0;
  14.     ntree * root = NULL;
  15.     int * mas[N];
  16.     int key;
  17.     node_q * nd;
  18.     FILE* f = fopen("input.txt", "r");
  19.     while(fscanf(f, "%i", &key) != EOF){
  20.             printf("%d   ", key);
  21.             root = build_tree(root, root, key);
  22.     }
  23.     q_tree * queue1 = init_queue(root);
  24.     //nd = dequeue(queue1);
  25.     int mn, * mnpr;
  26.     mn = root->key;
  27.     mnpr = 0;
  28.  
  29.  
  30.     printf("\n\n");
  31.     printf("PREORDER: ");
  32.     preorder(root);
  33.  
  34.     printf("\n\n");
  35.     printf("INORDER: ");
  36.     inorder(root);
  37.  
  38.     printf("\n\n");
  39.     printf("POSTORDER: ");
  40.     postorder(root);
  41.  
  42.     printf("\n\n");
  43.     printf("LEVELORDER: ");
  44.     printf("\n\nLEVELORDER:\n");
  45.    int lvl=-1;
  46.     while(queue1->head){
  47.         nd = dequeue(queue1);
  48.         if(lvl!=nd->lvl){
  49.            if(lvl!=0){
  50.                 if(!mnpr) mnpr = (int*)malloc(sizeof(int));
  51.                 *mnpr = mn;
  52.            }
  53.            mn = nd->node->key;
  54.            lvl = nd->lvl;
  55.         }
  56.         else{
  57.             if(mn>nd->node->key){
  58.                 mn = nd->node->key;
  59.             }
  60.         }
  61.         if(nd->node->left){
  62.             //printf("\n add left \n");
  63.             enqueue(queue1, nd->node->left, nd->lvl+1);
  64.         }
  65.         if(nd->node->right) {
  66.  
  67.             //printf("\n add right \n");
  68.                 enqueue(queue1, nd->node->right, nd->lvl+1);
  69.         }
  70.         printf("%d\t", nd->node->key);
  71.         free(nd);
  72.     }
  73.  
  74.     printf("\n\n");
  75.     printf("TASK: ");
  76.     //nTask = srchTask(root, lvl);
  77.     printf("%d", *mnpr);
  78.  
  79.     printf("\n\n%d nodes were deleted\n", free_tree(root));
  80.     fclose(f);
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement