为了账号安全,请及时绑定邮箱和手机立即绑定

程序如下,麻烦高手解释一下哦~

程序如下,麻烦高手解释一下哦~

湖上湖 2022-04-21 14:15:45
; Attributes: library function; int __thiscall std__locale__facet___scalar deleting destructor_(void *, char)??_Gfacet@locale@std@@UAEPAXI@Z proc neararg_0= byte ptr 4mov al, [esp+arg_0]push esimov esi, ecxtest al, 1mov dword ptr [esi], offset off_4055C8jz short loc_401F1A高手解释一下
查看完整描述

1 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

#include "stdio.h"
#include "stdlib.h"
#include "malloc.h"
#define Null 0
#define MAX 20

typedef struct ArcNode
{
int adjvex;
int weight;
struct ArcNode *nextarc;
}ArcNode,*AdjList;

typedef struct Graph
{
AdjList elem[MAX+1];
int vexnum;
int arcnum;
int GraphKind;
}Graph;

typedef struct Stack
{
int s[MAX];
int top;
}Stack;

void initStack(Stack *s)
{
(*s).top=0;
}

int Push(Stack *s, int e)
{
if((*s).top>=MAX) return 0;
else (*s).s[(*s).top++]=e;
}

int Pop(Stack *s, int *e)
{
if((*s).top<=0) return 0;
else *e=(*s).s[--(*s).top];
}

int StackEmpty(Stack s)
{
if(s.top==0)return 1;
else return 0;
}

void create(Graph *G)
{
int i, start, end; AdjList p;
for(i=0;i<=MAX;i++)
(*G).elem[i]=Null;
for(i=1;i<=(*G).arcnum;i++)
{
scanf("%d,%d",&start,&end);
p=(AdjList)malloc(sizeof(ArcNode));
p->adjvex=end;
p->nextarc=(*G).elem[start];
(*G).elem[start]=p;
if((*G).GraphKind==0)
{
p=(AdjList)malloc(sizeof(ArcNode));
p->adjvex=start;
p->nextarc=(*G).elem[end];
(*G).elem[end]=p;
}
}
}

int TopoSort(Graph G)
{
int i, count, indegree[MAX+1];
AdjList p; Stack S;
for(i=1;i<=G.vexnum;i++)
indegree[i]=0;
initStack(&S);
for(i=1;i<=G.vexnum;i++)
for(p=G.elem[i];p;p=p->nextarc)
++indegree[p->adjvex];
for(i=1;i<=G.vexnum;i++)
if(!indegree[i]) Push(&S,i);
count=0;
while(!StackEmpty(S))
{
Pop(&S,&i);
printf("v%d ",i);++count;
for(p=G.elem[i];p;p=p->nextarc)
if(!(--indegree[p->adjvex])) Push(&S,p->adjvex);
}
if(!count) return 1;
}

main()
{
Graph G;
printf("Please input the number of vex, arc and GraphKind:");
scanf("%d,%d,%d",&G.vexnum,&G.arcnum,&G.GraphKind);
create(&G);
printf("The outcome of TopoSort is:\n");
TopoSort(G);
}

查看完整回答
反对 回复 2022-04-24
  • 1 回答
  • 0 关注
  • 181 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信