资源简介
教学计划编制系统-数据结构课设源代码。VC6.0
代码片段和文件信息
#include
#include
#define MAX_VERTEX_NUM 100 //最大课程总数
#define NOTSTUDY 0
#define STUDY 1
#define STACK_INIT_SIZE 100 //存储空间的初时分配量
#define STACKINCREMENT 10 //存储空间的分配增量
typedef struct ArcNode{
int adjvex;
struct ArcNode *nextarc;
}ArcNode;
typedef struct VNode{
char name[24]; //课程名
int classid; //课程号
int credit; //课程的学分
int indegree; //该结点的入度
int state; //该节点的状态
ArcNode *firstarc; //指向第一条依附该顶点的弧的指针
}VNodeAdjList[MAX_VERTEX_NUM];
typedef struct{
AdjList vertices;
int vexnum arcnum;
}ALGraph;
typedef struct
{
int* base;
int* top;
int stacksize;
}SqStack;
void InitStack70310(SqStack* S)
{
S->base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));
if (!S->base)
{
printf(“ERROR“);
exit(1);
}
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
}
int StackEmpty70310(SqStack* S)
{
if(S->top==S->base)
return 1;
else
return 0;
}
void Push70310(SqStack *Sint e)
{
if(S->top - S->base >= S->stacksize)
{
S->base = (int*)realloc (S->base(S->stacksize + STACKINCREMENT) * sizeof(int));
if(!S->base)
{
printf(“ERROR“);
exit(1);
}
S->top = S->base + S->stacksize;
S->stacksize += STACKINCREMENT;
}
*S->top++ = e;
}
int Pop70310(SqStack *S int *e)
{
if(S->top == S->base) exit(1);
*e = * --(S->top);
return 0;
}
void FindInDegree70310(ALGraph G int indegree[])//求图中各节点的入度
{
int i;
for (i = 1; i <= G.vexnum; i++)
indegree[i] = 0;
for (i = 1; i <= G.vexnum; i++)
{
while (G.vertices[i].firstarc)
{
indegree[G.vertices[i].firstarc->adjvex]++;
G.vertices[i].firstarc = G.vertices[i].firstarc->nextarc;
}
}
}
void TopologicalSort_1_70310(ALGraph Gint numtermint uplcredit)
{
FILE *fp;
fp=fopen(“bianpai.txt““w“);
ArcNode *p;
SqStack S;
int indegree[MAX_VERTEX_NUM];//存放各节点的入度
int ij k;
int count; //课程编排数目计数器
int sumcredit;//每个学期的课程学分累加器
FindInDegree70310(G indegree);
for (i = 1; i <= G.vexnum; i++)
G.vertices[i].indegree=indegree[i];
InitStack70310(&S);
count=0;
k=0;
while(count!=G.vexnum && k<=numterm)
{
sumcredit=0;
for(i=1;i<=G.vexnum;i++) //入度为零的节点入栈,即无先修的课程入栈
if((G.vertices[i].indegree==0)&&(G.vertices[i].state==NOTSTUDY))
{
Push70310(&Si);
G.vertices[i].state = STUDY;//避免入度为零节点重复入栈
}
if(!StackEmpty70310(&S)&&(sumcredit<=uplcredit))
{
k= k+1;
printf(“\n“);
printf(“第%d个学期学得课程有:\n“k);
sumcredit = 0;
for(i=1;i<=G.vexnum;i++)//入度为零的节点入栈,即无先修的课程入栈
if((G.vertices[i].indegree==0)&&(G.vertices[i].state==NOTSTUDY))
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 8799 2013-06-19 10:03 数据结构课设源代码\12.cpp
文件 4236 2013-06-19 10:03 数据结构课设源代码\12.dsp
文件 529 2013-06-19 10:03 数据结构课设源代码\12.dsw
文件 33792 2013-06-19 10:03 数据结构课设源代码\12.ncb
文件 48640 2013-06-19 10:03 数据结构课设源代码\12.opt
文件 868 2013-06-19 10:03 数据结构课设源代码\12.plg
目录 0 2013-09-01 20:53 数据结构课设源代码
----------- --------- ---------- ----- ----
96864 7
评论
共有 条评论