Ordinal traversal algorithm for C-language binary tree sequential storage structure

Source: Internet
Author: User

#include  <stdio.h> #include  <stdlib.h> #include  <string.h> #define  __max_ length__ 20typedef struct sqstack{//Call Stack     int data[__MAX_LENGTH__];     int top;} sqstack;typedef struct sqbitree{//Sequential Storage binary Tree     elemType data[__MAX_LENGTH__];     int len;} sqbitree;//a two-tree Int tratree (sqbitree *t) {    sqstack *stack) that traverses a one-dimensional array as a storage structure by first order  = calloc (sizeof (Sqstack), 1);     stack->top = 0;//Stack Empty;     int root;    root = 0;//points to the root node;     while ( Stack->top) >-1) {//when the stack is not empty, enter the loop         while (root<__max_length_ _&&t->data[root]>= ' a ') {//             printf ("%c,", T->data[root]);//Access Node &NBSP;&NBSP;&Nbsp;         stack->data[stack->top] = root;// Node into the stack             stack->top ++;             root =  (root+1)  * 2-1;// Check the next Zuozi;         }        if ( STACK-&GT;TOP&NBSP;&GT;-1) {//stack non-null access, traverse right subtree;             stack->top --;            root  =  (stack->data[stack->top]+1) *2;        }     }}int main (int argc, char *argv[]) {    sqbitree *p =  calloc (sizeof (Sqbitree), 1);     strcpy (P->data, "Abcdefghij");     tratree (p);      return 0;} 

650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/06/67/wKiom1m3pGyhHY08AABTcaKN8oE984.png-wh_500x0-wm_ 3-wmp_4-s_3637921156.png "title=" icon "alt=" Wkiom1m3pgyhhy08aabtcakn8oe984.png-wh_50 "/>

This article is from the "Android_home" blog, make sure to keep this source http://yangzheng0809.blog.51cto.com/6024606/1964688

Ordinal traversal algorithm for C-language binary tree sequential storage structure

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.