杨辉三角链队列解法

来源:互联网 发布:高通骁龙超频软件 编辑:程序博客网 时间:2024/04/30 13:59
#include<stdio.h>#include<stdlib.h>#include"LinkQueue.h"#define N 188int main(void){datatype value;int i;LinkQueue node;LinkQueue *lqPtr=&node;LinkListNode *sPtr;Initialize_LinkQueue(lqPtr);//初始化队列Insert_LinkQueue(lqPtr, 0);//0、1、1、0入队Insert_LinkQueue(lqPtr, 1);Insert_LinkQueue(lqPtr, 1);Insert_LinkQueue(lqPtr, 0);for (i = 0; i < N; i++){sPtr = Delete_LinkQueue(lqPtr);value = sPtr->data + lqPtr->front->next->data;//队头两个元素求和生成新系数if (value != 0)printf("%d ", value);Insert_LinkQueue(lqPtr, value);//新系数入队if (lqPtr->front->next->data == 0){Insert_LinkQueue(lqPtr,0);//0作为每行的分隔符printf("\n");}}}

1 0
原创粉丝点击