宋清如至上主义者原文:请高手给把C中的8个错改下

来源:百度文库 编辑:高考问答 时间:2024/04/29 18:50:35
#include<string.h>
#include<ctype.h>
#include<malloc.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/* 函数结果状态代码 */
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
typedef int InfoType;
/* 图的邻接表存储表示 */
#define MAX_VERTEX_NUM 100
typedef struct ArcNode
{ int adjvex;
struct ArcNode *nextarc;
InfoType *info;
typedef struct VNode
{ VertexType data;
ArcNode *firstarc;
}VNode,AdjList[MAX_VERTEX_NUM];
typedef struct
{ AdjList vertices;
int vexnum,arcnum;
int kind;
}ALGraph;
int LocateVex(ALGraph G,VertexType u)
{ int i;
for(i=0;i<G.vexnum;++i)
if(strcmp(u,G.vertices[i].data)==0)
return i;
return -1;
}
Status CreateGraph(ALGraph *G)
/* 采用邻接表存储结构,构造没有相关信息的图G*/
{ int i,j,k;
VertexType va,vb;
ArcNode *p;
printf("dingdian shu: ");
scanf("%d",&(*G).vexnum);
printf("husgy : ");
scanf("%d",&(*G).arcnum);
printf("guanlianduishu,eg.1 2.:\n");
for(k=0;k<(*G).arcnum;++k)
{ scanf("%s%s",va,vb);
i=LocateVex(*G,va);
j=LocateVex(*G,vb);
p=(ArcNode*)malloc(sizeof(ArcNode));
p->adjvex=j;
p->info=NULL;
p->nextarc=(*G).vertices[i].firstarc;
(*G).vertices[i].firstarc=p;
}
return OK;
}
void FindInDegree(ALGraph G,int indegree[])
/* 求顶点的入度,算法调用 */
{ int i;
ArcNode *p;
for(i=0;i<G.vexnum;i++)
indegree[i]=0;
for(i=0;i<G.vexnum;i++)
{
p=G.vertices[i].firstarc;
while(p)
{ indegree[p->adjvex]++;
p=p->nextarc;
}
}
}
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct
{ SElemType *base;
int stacksize;
}SqStack;
Status InitStack(SqStack *S)
{ (*S).base = (SElemType *)malloc(sizeof(SElemType)*STACK_INIT_SIZE);
if(!(*S).base)
exit(OVERFLOW);
(*S).top=(*S).base;
(*S).stacksize=STACK_INIT_SIZE;
return OK;
}
Status StackEmpty(SqStack *S)
{ if(S.top==S.base)
return TRUE;
else
return FALSE;
}
Status Pop(SqStack *S,SElemType *e)
{
if((*S).top==(*S).base)
return ERROR;
e=*--(*S).top;
return OK;
}
Status Push(SqStack *S,SElemType e)
{ if((*S).top-(*S).base>=(*S).stacksize)
{
(*S).base=(ElemType *)realloc((*S).base,
((*S).stacksize+STACKINCREMENT)*sizeof(SElemType));
if(!(*S).base)
exit(OVERFLOW);
(*S).top=(*S).base+(*S).stacksize;
(*S).stacksize+=STACKINCREMENT;
}
*((*S).top)++=e;
return OK;
}
Status TopologicalSort(ALGraph G)
{
int i,k,count,indegree[MAX_VERTEX_NUM];
SqStack S;
ArcNode *p;
FindInDegree(G,indegree);
InitStack(&S);
for(i=0;i<G.vexnum;++i)
if(!indegree[i])
Push(&S,i);
count=0;
while(!StackEmpty(S))
{
Pop(&S,&i);
printf("i%s ",G.vertices[i].data);

++count;
for(p=G.vertices[i].firstarc;p;p=p->nextarc)
{
k=p->adjvex;
if(!(--indegree[k]))
Push(&S,k);
}
}
if(count<G.vexnum)
{printf("The AVO network has a cycle!\n");
return ERROR;
}
else
{printf("is a topological sort.\n");
}
}

在得到高手的回答之前,你必须:

1.给程序加上必要的注释
2.描述问题出现的状况
3.给出合适的系统和编译器
4.格式化你的源码

搞什么啊?
又是图又是栈
还用邻接表
还排序~~~…………

真不懂这个程序要干什么

不懂,或者说很难懂