| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 280 人关注过本帖
标题:十字链表的遍历不出来啊,编译没出错,求教啊各位
只看楼主 加入收藏
lianjiecuowu
Rank: 3Rank: 3
来 自:安徽
等 级:论坛游侠
帖 子:152
专家分:107
注 册:2011-5-20
结帖率:85.71%
收藏
 问题点数:0 回复次数:0 
十字链表的遍历不出来啊,编译没出错,求教啊各位
#include<iostream>
#include<cstdlib>

using namespace std;

class crosslist;
class snode
{
private:
    friend class crosslist;
public:
    int i;
    int j;
    int e;
    snode *right;
    snode *down;
};
typedef snode * snodepointer;
class crosslist
{
private:
    snodepointer *rhead;
    snodepointer *chead;
    int row;
    int col;
    int num;
public:
    crosslist();
    ~crosslist(){clear();}
    void clear();
    bool isempty();
    int getcolnum();
    int getrownum();
    int getnum();
    void creat_crosslist();
    void treavlist();
};
crosslist::crosslist()
{
    row=0;
    col=0;
    num=0;
    rhead=NULL;
    chead=NULL;
}
void crosslist::clear()
{
    if(rhead)
        delete []rhead;
    if(chead)
        delete []chead;
    row=0;
    col=0;
    num=0;
    rhead=NULL;
    chead=NULL;

}
bool crosslist::isempty()
{
    return num==0;
}
int crosslist::getcolnum()
{
    return col;
}
int crosslist::getrownum()
{
    return row;
}
int crosslist::getnum()
{
    return num;
}

void crosslist::creat_crosslist()
{
    int r=0,c=0,n=0,s;
    row=r;col=c;num=n;
    int k=0,ii,jj,ee;
    snodepointer *p,q;
    cout<<"请输入所创建的稀疏矩阵的--行数:   ";
    cin>>r;
    cout<<"请输入所创建的稀疏矩阵的--列数:  ";
    cin>>c;
    cout<<"请输入所创建的稀疏矩阵的--非零元素的个数:  ";
    cin>>n;
    rhead=new snodepointer[r];
    if(rhead==NULL)
    {
        cerr<<"memory allocation failare!"<<endl;
        return ;
    }
    for(k=0;k<r;k++)
        rhead[k]=NULL;
    chead=new snodepointer[c];
    if(chead==NULL)
    {
        cerr<<"memory allocation failare!"<<endl;
        return ;
    }
    for(k=0;k<c;k++)
        chead[k]=NULL;
    if(n)
    {
        p=new snodepointer[c];
        if(p==NULL)
        {
            cerr<<"memory allocation failare!"<<endl;
            return ;
        }
        for(s=0;s<c;s++)
            p[s]=chead[s]=NULL;
        for(k=0;k<n;k++)
        {
            cout<<"请输入非零元素所处的行  :";
            cin>>ii;
            cout<<"请输入非零元素所处的列 :";
            cin>>jj;
            cout<<"请输入非零元素的值     :";
            cin>>ee;
            snode *newp=new snode;
            if(newp==NULL)
            {
                cerr<<"memory allocation failare!"<<endl;
                return ;
            }
            newp->i=ii;
            newp->j=jj;
            newp->e=ee;
            newp->right=NULL;
            newp->down=NULL;
            if(rhead[newp->i-1]==NULL)
                rhead[newp->i-1]=newp;
            else
                q->right=newp;
            q=newp;
            if(chead[newp->j-1]==NULL)
                chead[newp->j-1]=newp;
            else
            {
                p[newp->j-1]->down=newp;
                p[newp->j-1]=newp;
            }   
            
        }
        delete []p;
    }
   
}
void crosslist::treavlist()
{
    for(int i=0;i<row;i++)
    {
        snodepointer p=rhead[i];
        while(p)
        {
            cout<<p->e<<"\t";
            p=p->right;
        }
    }
}
int main()
{
    crosslist C;
    C.creat_crosslist();
    C.treavlist();                                //为什么便利不出来啊,
    system("pause");
    return 0;
}

[ 本帖最后由 lianjiecuowu 于 2011-9-13 22:38 编辑 ]
搜索更多相关主题的帖子: class 十字 private include public 
2011-09-13 22:36
快速回复:十字链表的遍历不出来啊,编译没出错,求教啊各位
数据加载中...
 
   



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

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