| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 801 人关注过本帖
标题:C++新手学数据结构。。不知道怎么用#include<iomanip.h>这个函数库?求高手 ...
只看楼主 加入收藏
鱼鱼儿丸子
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-3-4
结帖率:100%
收藏
已结贴  问题点数:5 回复次数:3 
C++新手学数据结构。。不知道怎么用#include<iomanip.h>这个函数库?求高手指点杨辉三角中怎么用其库来弄出等腰三角形?
#include<iostream.h>
#include<iomanip.h>
enum error_code{success,overflow,underflow};
typedef struct node{
    int data;
struct node *next;
}node;
class queue{
public:
    queue();
    ~queue();
    bool empty()const;
    error_code get_front(int&x)const;
    error_code append(const int x);
    error_code serve();
private:
    int count;
    node*front,*rear;
};
queue::queue(){
    front=new node;
    rear=front;
    front->next =NULL;
count=0;
}
bool queue::empty ()const{
    return front==rear;
}
error_code queue::get_front (int&x)const{
    if(empty())return underflow;
    x=front->next->data ;
    return success;
}
error_code queue::append (const int x){
    node*s=new node;
    s->data =x;
    s->next =NULL;
    rear->next =s;
    rear=s;
    count++;
    return success;
}
error_code queue::serve (){
    node*u;
    if(empty())return underflow;
    u=front->next ;
    front->next=u->next ;
    delete u;
    count--;
    if(front->next==NULL)rear=front;
    return success;
}
 queue::~queue (){
    while(!empty())serve();
    delete front;}
void fun1(int n){
    int s1,s2;
    queue q;
    int i,j;
    cout<<setw(27)<<1<<endl;
    q.append(1);
    for(i=2;i<=n;i++){
        s1=0;
        cout<<setw(28-2*i);
        for(j=1;j<=i-1;j++){
            q.get_front (s2);
            q.serve ();
            cout<<" "<<s1+s2<<"  ";
            q.append (s1+s2);
            s1=s2;
        }
        cout<<" "<<1<<endl;
        q.append (1);
    }
}
void main()
{
    fun1(8);
}
搜索更多相关主题的帖子: next class 杨辉三角 include private 
2012-03-04 20:50
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:5 
放在坐标轴中计算出函数,然后再摆。不过没多大意义。
2012-03-06 10:18
鱼鱼儿丸子
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-3-4
收藏
得分:0 
回复 2楼 lucky563591
额。。能不能详细点。最好能把杨辉三角出等腰三角形的代码给下。。其实我排是排了,但还是有点不整齐。我总觉得不用这个用引号加空格挺丑的。
2012-03-06 13:51
非死亡!
Rank: 8Rank: 8
来 自:四川
等 级:蝙蝠侠
帖 子:179
专家分:760
注 册:2011-10-31
收藏
得分:0 
完全没意思 无聊啊

能力 技巧
2012-03-06 22:48
快速回复:C++新手学数据结构。。不知道怎么用#include<iomanip.h>这个函数库?求 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015044 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved