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

  • Satisfactory Essays

    Step 1: Examine the following algorithm as a base for how the program should flow. (Reference: Designing a Program, page 31).…

    • 777 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    ECET 370 Week 5 Lab 5

    • 650 Words
    • 3 Pages

    Exercise 1: Review of the Lecture Content Create a project using the ArrayList class and the Main class provided in DocSharing. The ArrayList class contains implementations of the first three search methods explained in this week's lecture: sequential, sorted, and binary search. The Main class uses these three methods. These programs test the code discussed in the lecture. Compile the project, run it, and review the code that is given carefully.…

    • 650 Words
    • 3 Pages
    Good Essays
  • 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
  • Better Essays

    printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); ttl_wt += stfor->wt; ttl_tt += stfor->tt; temp = np = stfor; del_node(np,1) ; ++i; } else { stfor->bt -= qt; stfor->tt = temp->tt + qt; printf(" %d \t\t %d\n\n",stfor->wt,stfor->tt); np = temp = stfor; del_node(np,2); ins_node(temp); } }while(stfor !=…

    • 401 Words
    • 2 Pages
    Better Essays
  • Good Essays

    Comp 220

    • 1463 Words
    • 6 Pages

    This lab will explore the use of pointers in several ways. Pointers will be used to dynamically allocate memory for new class objects on demand from the user, and they will be used to access class-member functions. Pointer arithmetic will be used to access and sort class objects according to criteria explained in the lab.…

    • 1463 Words
    • 6 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
  • 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
  • Better Essays

    The Education of Little Tree starts here, when Little Tree’s mom passed away and his grandparents took him in. He lived during a time of racism and prejudice that had lived on for many years between white people and Indians. He encounters this first hand on the bus ride to the wagon trail. His grandparents did not have tickets and when they entered the bus, the driver proceeded to make a joke and say “How!” and everyone on the bus laughed. Though Little Tree did not know this, he assumed that they were friendly people. They finally arrived at their stop and exited the bus and walked for an extended period of time to their cozy home hidden amongst the mountains.…

    • 1728 Words
    • 7 Pages
    Better 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
  • 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
  • Satisfactory Essays

    The Tender Tree Analysis

    • 338 Words
    • 2 Pages

    The Surrender Tree: Poems of Cuba’s Strength for Freedom is a poetry anthology written by Margarita Engle that has won multiple awards including the Newberry Award and the 2009 Américas Award. According to her website, she is the first Latino to have ever been awarded the Newberry. With such narrative verse that she writes in, it is hard for some to actually accept this style as poetry. According to Hintz and Tribunella, “the two terms (verse and poetry) are synonyms and simply mean the opposite of prose” (p. 89).…

    • 338 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Tree

    • 4528 Words
    • 19 Pages

    "A great battle lost or won is easily described, understood, and appreciated, but the moral growth of a great nation requires reflection, as well as observation, to appreciate it."…

    • 4528 Words
    • 19 Pages
    Better Essays
  • Satisfactory Essays

    CS 220 – Programming w/ Data Structures: You have missed one assignment and one quiz. Your instructor has extended your assignment due date to this Sunday, April 10. Your instructor has also let you to take your Quiz # 2 during his office hours during this week. Let me know if you need additional support to study for this quiz. Your grade to date in this class is 30.2/37 81.62% B.…

    • 354 Words
    • 2 Pages
    Satisfactory 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
  • 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