回 帖 发 新 帖 刷新版面

主题:[讨论]求高手,这个程序出现“产生访问违例段异常”

//求高手,这个程序出现“产生访问违例段异常”

#include<iostream>
#include<string>
#include<fstream>

using namespace std;

#define statue int 
typedef struct Elemtype{
    int e1;
    int e2;
    Elemtype *next;
} *Linktype;              //元素结构 

typedef struct{     //直表元素结构。 
        int m;
        Linktype e;
        Elemtype *cur;      //current  当前 
}HeadL,*Linkheadl; 

statue shuru(int n,HeadL *a)
{
       int i,j,k;
       Linktype p,q;
       for(i=0;i<n;i++)
       {
            q=(Linktype)malloc(sizeof(Elemtype));q->next=NULL;
            cin>>q->e1>>q->e2;
            for(j=a[0].m;j;j--)
            {
                if(a[j].e-(q->e1))
                {
                    for(;(a[j].cur)->next;a[j].cur=(a[j].cur)->next)  //调试时,这里显示:“产生访问违例段异常”
                    {
                         if(a[j].cur->e1>q->e1) 
                         {
                              p=a[j].cur;
                              a[j].cur=q;
                              q->next=p;
                              a[j].cur=a[j].e;
                              break;
                         }//if
                    }//for
                    if(!q->next) a[j].cur->next=q;
                }//if 
                if(!(j-1))
                {
                    a[0].m++;
                    k=a[0].m;
                    a[k].m=q->e1;
                }//if 
            }//for
       }//for
       k=a[0].m;
       HeadL h; 
       for(i=k-1;i;i--)
       {
            for(j=1;j<=i;j++)
            {
                 if(a[j].m>a[j+1].m) {h=a[j];a[j]=a[j+1];a[j+1]=h;}
            }//for 
       }//for 
       return 0;
}// 输入 


statue shuchu(HeadL *L)
{
       int i,k,j,n=L[0].m;
       Elemtype *elem;
       for(j=1;n;j++)
       {
            cout<<"第"<<j<<"组:"<<endl;
            for(k=0,i=L[0].m;i;i--)
            {
                 if(!L[i].e) continue;
                 if(L[i].e->e1<k) continue;
                 elem=L[i].cur;
                 cout<<elem->e1<<" "<<elem->e2<<endl;
                 L[i].cur=elem->next;
                 if(!L[i].cur)  n--;
            }//for 
       }//for
       return 0;
}

 
int main()
{
    int n;
    HeadL a[2000]; 
    a[0].m=1;a[1].m=0;a[1].e=NULL;a[1].cur=NULL; 
    cin>>n;
    shuru(n,a);
    shuchu(a);
    system("pause");
    return 0;
}

回复列表 (共1个回复)

沙发

你到底要一张什么样的表?段违例考虑内存越界的情况

我来回复

您尚未登录,请登录后再回复。点此登录或注册