| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 434 人关注过本帖
标题:一道求差集的题
只看楼主 加入收藏
lowryfly
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2012-11-28
结帖率:75%
收藏
 问题点数:0 回复次数:0 
一道求差集的题
#include <iostream>
using namespace std;
template<class ElemType>
class SqList
{
    protected:
    int count;
    int maxsize;
    ElemType*elems;
    public:
    SqList(int size=DEFAULT_SIZE);
    virtual ~SqList();
    int Length()const;
    bool Empty()const;
    void Clear();
    void Traverse(void(*Visit)(ElemType &));
    statusCode GetElem(int position,ElemType &e)const;
    statusCode SetElem(int position,const ElemType &e);
    statusCode Delete(int position,ElemType &e);
    statusCode Insert(int position,const ElemType &e);
    SqList(const SqList<ElemType>&copy);
    SqList<ElemType>&operator=(const SqList<ElemType>&copy);
};
bool SqList<ElemType>::Full()const_const()
{
    return count==maxSize;
}

void SqList<ElemType>::Init(int size)
{
    maxsize=size;
    if(elems!=NULL)delete []elems;
    elems=new ElemType[maxSize];
    count=0;
}

SqList<ElemType>::SqList(int size)
{
    elems=NULL;
    Init(size);
}
SqList<ElemType>::~SqList()
{
    delete []elems;
}
SqList<elemTyoe>::Length()const
{
    return count;
}
bool SqList<ElemType>::Empty()const
{
    return count==0;
}
void SqList<ElemType>::Clear()
{
    count=0;
}
void SqList<ElemType>::Traverse(void(*visit)(ElemType &))
{
    for(int curPosition=1;curPosition<=Length();curPosition++)
    {
        (*visit)(elems[curPosition-1]);
    }
}
statusCode SqList<ElemType>::GetElem(int position;ElemType &e)const
{
    if(position<1||position>Length())
    {
        return NOT_PRESENT;
    }
    else
    e=elems[position-1];
    return ENTRY_FOUND;
}
statusCode SqList<ElemType>::SetElem(int position;const ElemType &e)
{
       if(position<1||position>Length())
        {
              return RANGE_ERROR;
           }
           else
           {
          elems[position-1]=e;
          return SUCCESS;
       }
}



void difference(const SqList<ElemType>&la,const SqList<ElemType>&lb,
                const SqList<ElemType>&lc)
{
    ElemType aItem,bItem;
    lc.Clear();
    for(int aPosition=1;aPosition<=la.length();aPosition++)
    {
        la.GetElem(aPosition,aItem);
        bool isExist=flase;
        for(int bPosition=1;bPosition<=la.length();bPosition++)
        {
            lb.GetElem(bPosition,bItem);
            if(aItem=bItem)
            {
                isExist=true;
                break;
            }
        }
        if(!isExist)
        {
            lc.Insert(lc.Length()+1,aItem);
        }
    }
}
大神们帮忙改改,给个能运行的完整代码,谢谢
搜索更多相关主题的帖子: void namespace position include public 
2013-01-23 16:07
快速回复:一道求差集的题
数据加载中...
 
   



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

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