Chapter 2 tree and binary tree-binary tree sequential storage genealogy

Source: Internet
Author: User
/** This program stores three generations of Qing Dynasty Royal family tree in a binary tree sequence and outputs the family tree. (Only the eldest son and second son are stored ). */# Include <stdio. h> # include <stdlib. h> # include <math. h ># define max_tree_size 7 typedef struct family {/* family tree info */Char name [20];} family; typedef struct sqbitree {/* binary tree */family * ELEM ;} sqbitree; int initbitree (sqbitree * l) {/* construct an empty binary tree */L-> ELEM = (Family *) malloc (max_tree_size * sizeof (family); If (! L-> ELEM) return 0; return 1;} int input (sqbitree * l) {/* Information in the input binary tree */int I; printf ("Please input names in order. \ n "); for (I = 0; I <= MAX_TREE_SIZE-1; I ++) {scanf (" % s ", L-> ELEM [I]. name);} return 1;} int output (sqbitree * l) {/* output information in the binary tree */int I; printf ("the family tree is as below. \ n "); for (I = 0; I <= MAX_TREE_SIZE-1; I ++) {printf (" % s ", L-> ELEM [I]. name); if (I = 0 | I = 2 | I = 6) printf ("\ n");} return 1;} int main () {sqbitree L; if (Initbitree (& L) = 1) {input (& L); output (& L);} elseprintf ("the space for initialization is not enough! \ N "); Return 0;}/** test case: * input: * nuerhatchi * * du nikanyuetossoto * output: * nuerkhachi * * du nikanyueto Shuo */

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.