+ -
当前位置:首页 → 问答吧 → 请教Stack around the variable 'v1' was corrupted,我这个怎么解决?是有关邻接多重表的建立的。

请教Stack around the variable 'v1' was corrupted,我这个怎么解决?是有关邻接多重表的建立的。

时间:2011-11-21

来源:互联网

C/C++ code
#include <iostream>
using namespace std;

//----------------无向图的邻接多重表存储结构的定义
//------------书P116

const int NUM=100;
const int Num=2;//每个顶点所表示的数据
typedef char VertexType[Num];

 
typedef struct EBox
{
    int mark;
    int ivex,jvex;
    struct EBox *ilink,*jlink;
    
}EBox;
typedef struct VexBox
{
    VertexType data;
    EBox *firstedge;
}VexBox;
typedef struct 
{
    VexBox adjmulist[NUM];
    int vexnum,edgenum;//顶点数,边数
}AMLGraph;




int LocateVex(AMLGraph G,VertexType u)
{
    int i;
    for(i=0;i<G.vexnum;i++)
        {if(strcmp(u,G.adjmulist[i].data)==0)
        return i;}
    return -1;
}

int CreateGraph(AMLGraph &G)
{
    cout<<"请输入图的顶点数、弧数:";
    cin>>G.vexnum;   //输入图当前的顶点数
    cin>>G.edgenum;    //输入图当前的边数

    cout<<"请输入每个顶点的值:"<<endl;
    for(int i=0;i<G.vexnum;i++)
    {
        cin>>G.adjmulist[i].data;     //输入顶点值
        G.adjmulist[i].firstedge=NULL;//初始化指针为空
    }

    VertexType v1,v2;
    EBox *p;
    int i,j;                              //每条弧所关联的两个结点
    for(int k=0;k<G.edgenum;k++)
    {
        cout<<"请输入第"<<k+1<<"弧的始点和终点:";
        cin>>v1;cin>>v2;
        i=LocateVex(G,v1);j=LocateVex(G,v2);//确定v1和v2在图G中的位置
        cout<<"i="<<i<<"      "<<"j="<<j<<endl;
        cout<<"G.adjmulist[i].firstedge"<<G.adjmulist[i].firstedge<<"      "<<"G.adjmulist[j].firstedge"<<G.adjmulist[j].firstedge;
        p=(EBox *)malloc(sizeof(EBox));
        //p = new (EBox);
        cout<<"p="<<p<<endl;
                              //对结点域进行赋值
        (*p).mark=0;
        (*p).ivex=i;
        (*p).jvex=j;
        (*p).ilink=G.adjmulist[i].firstedge;
        (*p).jlink=G.adjmulist[j].firstedge;
        G.adjmulist[i].firstedge=G.adjmulist[j].firstedge=p;    
        
    }
    return 1;
}

int main()
{
    AMLGraph g;
    CreateGraph(g);
    return 0;
}

作者: sure631440254   发布时间: 2011-11-21

cin>>v1;cin>>v2;

输入字符超过1个会越界啊

作者: oo   发布时间: 2011-11-22

楼上大神,我是楼主的同学,敢问这个越界问题怎么修改啊,楼主说给全分

作者: qianse1314   发布时间: 2011-11-22

热门下载

更多