zoukankan      html  css  js  c++  java
  • 图的建立及输出其先序序列,中序序列,后续序列

     1 #include<stdio.h>
     2 #include<malloc.h>
     3 typedef struct node{
     4     char data;
     5     struct node *left;
     6     struct node *right;
     7 }Node;
     8 
     9 int i = 0;
    10 char str[100];
    11 
    12 void create(Node** p){
    13     if(str[i] == '')
    14         return ;
    15     if(str[i++] != '#'){
    16         *p = (Node*)malloc(sizeof(Node));
    17         (*p)->left = (*p)->right = NULL;
    18         (*p)->data = str[i-1];
    19         create(&(*p)->left);
    20         create(&(*p)->right);
    21     }
    22 }
    23 
    24 void print(Node *p){
    25     if(p != NULL && p->data != '#'){
    26         printf("%c ",p->data);
    27         print(p->left);
    28         print(p->right);
    29     }
    30 }
    31 
    32 void print_2(Node *p){
    33     if(p != NULL && p->data != '#'){
    34         print_2(p->left);
    35         printf("%c ",p->data);
    36         print_2(p->right);
    37     }
    38 }
    39 
    40 void print_3(Node *p){
    41     if(p != NULL && p->data != '#'){
    42         print_3(p->left);
    43         print_3(p->right);
    44         printf("%c ",p->data);
    45     }
    46 }
    47 
    48 int main(){
    49     gets(str);
    50     Node *head = NULL;
    51     create(&head);
    52     printf("先序序列:");
    53     print(head);
    54     printf("
    中序序列:");
    55     print_2(head);
    56 
    57     printf("
    后序序列:");
    58     print_3(head);
    59 
    60     return 0;
    61 }
  • 相关阅读:
    10 给予scrapy-redis的分布式爬虫
    pandas 01 序列和数据库昂
    如何控制分布式爬虫结束
    动态导入模块
    docker
    09 scrapy中间件
    scrapy 获取settings中的内容
    session对象的cookies
    文本检测-1-MSER
    CTW1500数据集介绍
  • 原文地址:https://www.cnblogs.com/yfs123456/p/5510448.html
Copyright © 2011-2022 走看看