注册 登录
编程论坛 C++教室

C++新手学数据结构。。不知道怎么用#include<iomanip.h>这个函数库?求高手指点杨辉三角中怎么用其库来弄出等腰三角形?

鱼鱼儿丸子 发布于 2012-03-04 20:50, 801 次点击
#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);
}
3 回复
#2
lucky5635912012-03-06 10:18
放在坐标轴中计算出函数,然后再摆。不过没多大意义。
#3
鱼鱼儿丸子2012-03-06 13:51
回复 2楼 lucky563591
额。。能不能详细点。最好能把杨辉三角出等腰三角形的代码给下。。其实我排是排了,但还是有点不整齐。我总觉得不用这个用引号加空格挺丑的。
#4
非死亡!2012-03-06 22:48
完全没意思 无聊啊
1