Preview

Binary Tree Representations

Satisfactory Essays
Open Document
Open Document
404 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Binary Tree Representations
#include
#include

/* ------------------------------------------------------------------------- */ // global variable declaration

struct tree // definition of a tree structure
{
struct tree *left; // pointer pointed to left child node int data; // data value of current node struct tree *right; // pointer pointed to right child node
};
typedef struct tree *btree; // declaration of a new type of tree structure

/* ------------------------------------------------------------------------- */ // declaration of prototype function that will be used in the following program bTree Insert_Node(bTree, int); // insert node of binary tree bTree Create_Btree(int *, int); // create binary tree void Print_Btree(bTree ); // print a created binary tree

/* ------------------------------------------------------------------------- */ /* main program: input array element, set up a linked list type of binary */ /* tree and print the binary tree */
/* ------------------------------------------------------------------------- */ void main(void)
{
bTree root = NULL; // pointer of tree root node

int i,index; // variable for loop count and length of array int value; // variable used to store input data temporarily int nodeList[20]; // array to store input data

printf("\nPlease input the elements of binary tree (Exit for 0):\n"); index = 0;

/* --------------------------------------------------------------------- */ // read and reserve input data into array nodeList scanf("%d",&value); while(value != 0) // read 'til a '0' is input
{
nodeList[index] = value; index++; scanf("%d",&value);
}

/* --------------------------------------------------------------------- */ // create a binary tree using linked list root = Create_Btree(nodeList,index);

// --------------------------------------------------------------------- */ // print the content of created binary tree above
Print_Btree(root);
}

/*

You May Also Find These Documents Helpful

  • Good Essays

    Nt1310 Unit 1 Test Paper

    • 381 Words
    • 2 Pages

    1. Create an insert function that will take nodes and add them up in the binary tree.…

    • 381 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    MATH203 PHASE3

    • 268 Words
    • 1 Page

    The tree is not a binary tree because some nodes have more than two children. If a direct link…

    • 268 Words
    • 1 Page
    Satisfactory Essays
  • Powerful Essays

    NATIVE REPRESENTATIONS 2

    • 22749 Words
    • 94 Pages

    As we have seen in previous parts of this text, Native history is different from…

    • 22749 Words
    • 94 Pages
    Powerful Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    19.Write a program that prompts the user to enter a character and on subsequence line print its ASCII code in binary and the number of 1 bit in its ASCII code. Page: 136…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Info1105

    • 951 Words
    • 4 Pages

    LinkedListNode.java (and LinkedListNodeTest.java), an implementation of the Node ADT SortedLinkedList.java (and SortedLinkedListTest.java), an implementation of the LinkedList ADT Racer.java (and RacerTest.java), which is stored in your linked list and explained below Scoreboard.java (and ScoreboardTest.java), which uses your linked list and is explained below…

    • 951 Words
    • 4 Pages
    Good Essays
  • Satisfactory Essays

    CS305 Final Exam Questions

    • 1044 Words
    • 6 Pages

    c. It increments the stack pointer (by 2 or 4) and copies the operand into the stack at the location pointed to by the stack pointer.…

    • 1044 Words
    • 6 Pages
    Satisfactory Essays
  • Good Essays

    Chapter 6 solutions

    • 4145 Words
    • 41 Pages

    b. Modify the reverse-display program so that the user can enter up to 10 numbers…

    • 4145 Words
    • 41 Pages
    Good Essays
  • Powerful Essays

    Cen 254 Data Structure

    • 924 Words
    • 4 Pages

    keys 30, 40, 24, 58, 48, 26, 11, 13 (in this order). Draw the tree after each…

    • 924 Words
    • 4 Pages
    Powerful Essays
  • Good Essays

    Has there ever been a time where you said something you believed in but were shut down because of it? Did you fight or back down? In the story Song of the Trees by Mildred T. Taylor, there is a girl and her family who strongly believe that the trees shouldn’t be cut down by white men. The white men of course don’t care that it isn’t their land, or that it is her family's land. Everyone should stand for what they believe.…

    • 792 Words
    • 4 Pages
    Good Essays
  • Good Essays

    Parallel Arrays

    • 427 Words
    • 2 Pages

    Key in saving wasted memory. The nodes of a linked data structure can also be moved individually to different locations without affecting the logical connections between them, unlike arrays. With due care, a process can add or delete nodes to one part of a data structure even while other processes are working on other parts. On the other hand, access to any particular node in a linked data structure requires following a chain of references that stored in it. If the structure has n nodes, and each node contains at most b links, there will be some nodes that cannot be reached in less than log b n steps. For many structures, some nodes may require worst case up to n -1 steps.…

    • 427 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Question 1: There is a binary tree of size N. All nodes are numbered between 1-N(inclusive). There is a N*N integer matrix Arr[N][N], all elements are initialized to zero. So for all the nodes A and B, put Arr[A][B] = 1 if A is an ancestor of B (NOT just the immediate ancestor).…

    • 359 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    // FREQUENT SUBTREE MINING ALGORITHM... #include #include #include #include #include #include using namespace std; FILE *fp; int no_of_nodes=0, string_ctr=0, vect_ctr=0, vect_ctr1=0,pos_ctr=0,*pos; struct MyNode { string name; vector children; }*myroot, *myroot1, **tree_pattern, **subtree_pattern; //FUNCTION PROTOTYPES DECLARATION ... static void print_element_names(xmlNode *); static MyNode* preprocess(xmlNode *,MyNode *, int); int printMyNode(MyNode *); void print(MyNode **, int); void print_pos_array(int *,int); int check_child(MyNode *, MyNode *); int main() { xmlDoc *doc = NULL; xmlDoc *doc1 = NULL; xmlNode *root_element = NULL; xmlNode *root_element1 = NULL;…

    • 488 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    c++ balaguruswamy

    • 1703 Words
    • 22 Pages

    Top of Form Technical Interview Questions Google Search C++ Interview Questions C# Interview Questions C Interview Questions ......... More pub-7003540323 ISO-8859-1 active GALT:#008000;G C ++ Aptitude Questions C Aptitude Questions 2 ......... More 3422992112 ISO-8859-1 Aptitude Interview Questions 1 en Bottom of Form Tutorials C Tutorial C++ Tutorial C Aptitude Questions and Answers…

    • 1703 Words
    • 22 Pages
    Better Essays
  • Powerful Essays

    Data Structure Assignment

    • 4612 Words
    • 19 Pages

    * The left subtree of a node contains only nodes with keys less than the node 's key.…

    • 4612 Words
    • 19 Pages
    Powerful Essays
  • Powerful Essays

    For the hexadecimal main memory address 111111, 666666, BBBBBB, show the following information, in hexadecimal format:…

    • 1443 Words
    • 6 Pages
    Powerful Essays

Related Topics