• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

利用向量实现集合的交于并,可以帮我挑挑错或者给我一份正确源代码吗?

#ifndef-Vector-H
enum boolean {FALSE,TRUE};
typedef enum boolean Bool;
typedef  int  ElementType ;
struct vector
{
        ElementType *elements;
        int ArraySize;
        int VectorLength;
};
typedef struct vector Vector;


void GetArray(Vector*);
void InitVector(Vector*,int sz);
ElementType GetNode(Vector*v,int i);
void FreeVector(Vector*);
int Find(Vector*,ElementType);
Bool Remove(Vector*,int i);
#endif
以上是工程里的头文件








#include


void GetArray(Vector *V)
{
        V->element=(ElementType*)malloc(sizeof(ElementTyepe)*V->Arraysize);
        if(V->element==NULL)
                printf("Memory Allocation Error!\n");
}


void InitVector (Vector*V,int sz)  /*初始化一个数组,建立一个最大长度为sz的数组*/
{
        if(szArraySize=sz;
                v->VectorLength=0;
                GetArray(V);
        }
}


ElementType GetNode(Vector*V,int i)  /*取向量中的第i个节点,若存在,则返回该结点的值;否则返回NULL*/
{
        return(i=V->VectorLength)?NULL:V->elements;
}
void FreeVector(Vector*V) /*释放向量存储空间*/
{
        free(V->elements);
        int Find(Vector*V ElementType x)  /*查找值为x的的结点,若找到,则返回结点序号;否则返回-1*/


        {
                int i;
                for (i=0;ielements==x)
                        if(V->elements==x)
                                return i;
                        return -1;
        }
void
Bool Insert(Vector *V,ElementTypex,int i)   /*在向量第i个位置插入值为x的结点,成功返回TURE,否则返回FALSE*/
{
    int j;
        if(V->VectorLength==V->ArraySize)
        {


                printf("向量储存空间已满\n");
                return FALSE;
        }
        else
        {
                for(j=V->VectorLength-1;j>=i;j--)
                V->elements[j+1]=V->elements[j];
                V->element=x;
                V->VectorLength++;
                return TURE;
        }
}


Bool Remove(Vecor *V,int i)
{
        int j;


        if(V->VectorLength==0)
        {
                printf("向量为空\n")
                        return FALSE;
        }
        else if (iV->VectorLength-1)
        {
                printf("删除位置错误\n");
                return FALSE;
        }
        else
                for(j=i;jVectorLength-1;j++)
                        V->elements[j]=V->elements[j+1];
                V->VectorLength--;
                return TURE;
}


Vector *Union(Vector *Va,Vector *Vb)
{
        int m,n,i,j,k;
        int x;
        Vector *Vc=(Vector)malloc(sizeof(Vector));
        n=Va->VectorLength;
        m=Vb->VectorLength
        InitVector(Vc,m+n);
        j=0;
        for(i=0;iVectorLength;
        InitVector(Vc,(m>n)?n:m);
        i=0;
        j=0;

        while(i

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!