#include<iostream>
using namespace std;
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
typedef int QElemType;
typedef struct QNode{
QElemType data;
QNode *next;
}QNode,*QueuePtr;
typedef struct{
QueuePtr front;
QueuePtr rear;
}LinkQueue;
Status InitQueue(LinkQueue &Q){
Q.front=new QNode;
if(Q.front==NULL)
return OVERFLOW;
Q.front->next;
Q.rear=Q.front;
return OK;
}
Status EnQueue(LinkQueue &Q,QElemType e){
QNode *p=new QNode;//插入元素e为Q的新的队尾元素
if(p==NULL)
return OVERFLOW; //存储分配失败
p->data=e;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;//修改队尾指针
return OK;
}
Status DeQueue(LinkQueue &Q,QElemType &e){
if(Q.front==Q.rear)//删除Q的队头元素,用e返回其值,并返回OK
return ERROR; //若队列为空,则返回ERROR
QNode *p=Q.front->next;//p指向队头元素
e=p->data;//e保存队头元素的值
Q.front->next=p->next;//修改头指针
if(Q.rear==p)
Q.rear=Q.front;//最后一个元素被删,队尾指针指向头结点
delete p;
return OK;
}
void YangHui(QElemType num){
int i,j,k,t,s;
LinkQueue p;
InitQueue(p);
EnQueue(p,1);
EnQueue(p,1);
s=0;
for(i=1;i<=num;i++){
cout<<endl;
EnQueue(p,0);
for(j=1;j<=i+2;j++){
DeQueue(p,t);
EnQueue(p,s+t);
s=t;
if(j!=i+2)
printf("%4d",s);
}
}
}
int main(){
int N;
cout<<"请输入你所要打印的行数:"<<endl;
cin>>N;
YangHui(N);
return 0;
}