Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ads_tree_pure_c.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define N 10
- #define R 60
- int main(){
- int nTask=0;
- int lmax=0, kmax=0;
- int klvl=0;
- ntree * root = NULL;
- int * mas[N];
- int key;
- node_q * nd;
- FILE* f = fopen("input.txt", "r");
- while(fscanf(f, "%i", &key) != EOF){
- printf("%d ", key);
- root = build_tree(root, root, key);
- }
- q_tree * queue1 = init_queue(root);
- //nd = dequeue(queue1);
- int mn, * mnpr;
- mn = root->key;
- mnpr = 0;
- printf("\n\n");
- printf("PREORDER: ");
- preorder(root);
- printf("\n\n");
- printf("INORDER: ");
- inorder(root);
- printf("\n\n");
- printf("POSTORDER: ");
- postorder(root);
- printf("\n\n");
- printf("LEVELORDER: ");
- printf("\n\nLEVELORDER:\n");
- int lvl=-1;
- while(queue1->head){
- nd = dequeue(queue1);
- if(lvl!=nd->lvl){
- if(lvl!=0){
- if(!mnpr) mnpr = (int*)malloc(sizeof(int));
- *mnpr = mn;
- }
- mn = nd->node->key;
- lvl = nd->lvl;
- }
- else{
- if(mn>nd->node->key){
- mn = nd->node->key;
- }
- }
- if(nd->node->left){
- //printf("\n add left \n");
- enqueue(queue1, nd->node->left, nd->lvl+1);
- }
- if(nd->node->right) {
- //printf("\n add right \n");
- enqueue(queue1, nd->node->right, nd->lvl+1);
- }
- printf("%d\t", nd->node->key);
- free(nd);
- }
- printf("\n\n");
- printf("TASK: ");
- //nTask = srchTask(root, lvl);
- printf("%d", *mnpr);
- printf("\n\n%d nodes were deleted\n", free_tree(root));
- fclose(f);
- return 0;
- }
Add Comment
Please, Sign In to add comment