小狸猫--陈乘 的个人资料chencheng照片日志列表 工具 帮助

日志


    用队列输出杨晖三角

    //本程序使用C++编写//
     
     
    // sequeue.h//
    // sequeue.h: interface for the sequeue class.
    //
    //////////////////////////////////////////////////////////////////////
    #if !defined(AFX_SEQUEUE_H__29A28262_0EBE_4813_BAAF_FDA1156DFABD__INCLUDED_)
    #define AFX_SEQUEUE_H__29A28262_0EBE_4813_BAAF_FDA1156DFABD__INCLUDED_
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    class sequeue 
    {
    public:
     sequeue                         ();
     virtual ~sequeue                ();
     void SetNullSequeue             ();
     bool ChargeEmpty                ();
     bool ChargeFull                 ();
     int& GetFrontELe                ();
     int& InsertSequeue              ();
     int& InsertZero                 ();
     int& InsertZero                 (int meaningless);
     int& JumpOut                    ();
    private:
     int data[10];
     int front;
     int rear;
    };
    #endif // !defined(AFX_SEQUEUE_H__29A28262_0EBE_4813_BAAF_FDA1156DFABD__INCLUDED_)
     
     
    // sequeue.cpp// 
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
     
     
    // sequeue.cpp: implementation of the sequeue class.
    //
    //////////////////////////////////////////////////////////////////////
    #include "stdafx.h"
    #include "sequeue.h"
    #include <iostream>
    using namespace std;
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////
     
    sequeue::sequeue()                      //构造队列//
    {
     front = 10 - 1;
     data[0] = 0;
     data[1] = 1;
        data[2] = 1;
     data[3] = 0;
     rear = 3;
     cout << "1" << endl;
     cout << "1" << " " << "1" << endl;
    }
    sequeue::~sequeue()
    {
    }
    bool sequeue::ChargeEmpty()            //判断队列是否为空//
    {
     if(rear==front)
      return true;
     else
      return false;
    }
    bool sequeue::ChargeFull()                 //判断队列是否为满//
    {
     if((rear+1)%10 == front)
      return true;
     else
      return false;
    }
    int& sequeue::GetFrontELe()               //取出队列头元素//
    {
     if(data[front]!=0)
      cout << data[front] << " ";
     return data[front];
    }
    int& sequeue::InsertSequeue()                      //插入队列//
    {
     int x;
     if(ChargeFull())
     {
      cout << "数组溢出" << endl;
      exit(0);
     }
     else
     {
      x = GetFrontELe() + JumpOut();
      rear = (rear+1)%10;
      data[rear] = x;
      return data[rear];
     }
    }
    int& sequeue::InsertZero()          //插入队列前的零//
    {
     if(ChargeFull())
     {
      cout << "数组溢出" << " ";
      exit(0);
     }
     else
     {
      JumpOut();
      rear = (rear+1)%10;
      data[rear] = 0;
      return data[rear];
     }
    }
    int& sequeue::InsertZero(int meaningless)                  //插入队列后的零//
    {
     if(ChargeFull())
     {
      cout << "数组溢出" << " ";
      exit(0);
     }
     else
     {
      rear = (rear+1)%10;
      data[rear] = 0;
      return data[rear];
     }
    }
    int& sequeue::JumpOut()                     //跳出队列//
    {
     int x;
     if(ChargeEmpty())
     {
      cout << "数组为空" << endl;
      exit(0);
     }
     else
     {
      x = front;
      front = (front+1)%10;
         return data[front];
     }
    }
    void sequeue::SetNullSequeue()                 //置空队列//
    {
     rear = front;
    }
     
     
    //main//
    /////////////////////////////////////////////////////////////////////////////////////////////////////////
     
     
    // chencheng_数组队列实现杨晖三角.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include "sequeue.h"
    #include <iostream>
    using namespace std;

    int main(int argc, char* argv[])
    {
     sequeue Queue;
     for(int i=2; i<7; i++)
     {
      Queue.InsertZero();
      for(int j=1; j<=(i+1); j++)
       Queue.InsertSequeue();
      Queue.InsertZero(1);
      cout << endl;
     }
     return 0;
    }

    评论 (1)

    请稍候...
    很抱歉,您输入的评论太长。请缩短您的评论。
    您没有输入任何内容,请重试。
    很抱歉,我们当前无法添加您的评论。请稍后重试。
    若要添加评论,需要您的家长授予您相应权限。请求权限
    您的家长禁用了评论功能。
    很抱歉,我们当前无法删除您的评论。请稍后重试。
    您已超过了一天之内允许提供的评论数上限。请在 24 小时后重试。
    因为我们的系统表明您可能在向其他用户提供垃圾评论,您的帐户已禁用了评论功能。如果您认为我们错误地禁用了您的帐户,请联系 Windows Live 支持部门
    完成下面的安全检查,您提供评论的过程才能完成。
    您在安全检查中键入的字符必须与图片或音频中的字符一致。

    若要添加评论,请使用您的 Windows Live ID 登录(如果您使用过 Hotmail、Messenger 或 Xbox LIVE,您就拥有 Windows Live ID)。登录


    还没有 Windows Live ID 吗?请注册

    陌陌发表:
    要分为三个源文件编译~~
    4 月 13 日

    引用通告

    此日志的引用通告 URL 是:
    http://chenchengnet.spaces.live.com/blog/cns!4DB68F293712C29B!112.trak
    引用此项的网络日志