zoukankan      html  css  js  c++  java
  • 输出如下图形

    *

    **
    ***
    ****
    *****
    ****
    ***
    **

    *

    这道题本来也不难。

    CSDN的牛们也各有奇招。

    但正好理解OSG的node遍历,因此就写了一个旁门左道的。 

    #include <iostream>

    class node
    {
    public:
        node(
    void){;}
        
    ~node(void){;}
        
    virtual void print(void= 0;
    };

    class group:public node
    {
    public:
        group(
    void):_child(NULL){;}
        
    ~group(void){ delete _child;}
        
    void print(void)
        {
            curdepth
    ++;
            
    for (int j=0; j<curdepth; j++)
            {
                printf(
    "*");
            }
            
    if (_child)
            {
                printf(
    "\n");
                _child
    ->print();
            }
            
    else
            {
                printf(
    "\n");
            }
            
    if (_child)
            {
                
    for (int j=0; j<curdepth; j++)
                {
                    printf(
    "*");
                }
                printf(
    "\n");
            }
            curdepth
    --;
        }
        node 
    * _child;
        
    static int curdepth;
    };
    int group::curdepth = 0;


    int main(int argc, char** argv)
    {
        
    int asteriskmaxnum = 5;
        group 
    * ptr = NULL;

        group 
    * iter = ptr;
        
    for (int i =0; i<asteriskmaxnum; i++)
        {
            
    if (!iter)
            {
                ptr 
    = new group;
                iter 
    = ptr;
            }
            
    else
            {
                iter
    ->_child = new group;
                iter 
    = (group *)(iter->_child);
            }
        }

        ptr
    ->print();
        system(
    "PAUSE");
        
    return 0;


  • 相关阅读:
    mysql 约束条件介绍
    mysql 约束条件目录
    mysql 日期类型
    mysql float 浮点型
    mysql int 整数类型 解释显示宽度 和 存储宽度
    mysql 整数类型 数值类型 tinyint
    【洛谷P4096】Eden 的博弈树
    【GMOJ6824】英雄联盟
    【GMOJ6826】隔膜
    【POJ 2420】A Star not a Tree?
  • 原文地址:https://www.cnblogs.com/mumuliang/p/2107661.html
Copyright © 2011-2022 走看看