教学计划编制源代码由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“教学计划编制系统”。
#include #include #include #include #include #include
#define TRUE 1 #define FALSE 0 #define OK 1 #define ERROR 0 #define INFEASIBLE-1 #define Status int #define Boolean int #define MAX_NAME 10 #define MAXCLASS 100 #define MAX_VERTEX_NUM 100 #define STUDY 1 #define NOTSTUDY 0 #define STACK_INIT_SIZE 10 #define STACKINCREMENT 2 typedef int SElemType;typedef struct SqStack {
SElemType *base;
SElemType *top;
int stacksize;}SqStack;typedef char VertexType[MAX_NAME];typedef struct ArcNode {
int adjvex;//该弧指向顶点的位置
struct ArcNode *nextarc;//指向下一条弧的指针 }ArcNode;typedef struct {
VertexType data;
int credit;
int state;
int indegree;
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
if(strcmp(u,G.vertices[i].data)==0)
return i;
return-1;} Status CreateGraph(ALGraph &G){
int i,j,k;
VertexType va,vb;
ArcNode *p;
printf(“请输入教学计划的课程数: ”);
scanf(“%d”,&G.vexnum);
printf(“请输入拓扑排序所形成的课程先修关系的边数: ”);
scanf(“%d”,&G.arcnum);
printf(“请输入%d个课程的代表值(<%d个字符):n”,G.vexnum,MAX_NAME);
for(i=0;i
{
scanf(“%s”,&G.vertices[i].data);
G.vertices[i].firstarc=NULL;
G.vertices[i].state=NOTSTUDY;
G.vertices[i].indegree=0;
}
printf(“请输入%d个课程的学分值(<%d个字符):n”,G.vexnum,MAX_NAME);
for(i=0;i
{
scanf(“%d”,&(G.vertices[i].credit));
}
printf(“请顺序输入每条弧(边)的弧头和弧尾(以空格作为间隔):n”);
for(k=0;k
{
scanf(“%s%s”,va,vb);
i=LocateVex(G,va);
j=LocateVex(G,vb);
p=(ArcNode*)malloc(sizeof(ArcNode));
p->adjvex=j;
p->nextarc=G.vertices[i].firstarc;
G.vertices[i].firstarc=p;
}
return OK;} Status Display(ALGraph G){
int i;
ArcNode *p;
printf(“%d个顶点:n”,G.vexnum);
for(i=0;i
printf(“%s”,G.vertices[i].data);
printf(“n%d条弧(边):n”,G.arcnum);
for(i=0;i
{
p=G.vertices[i].firstarc;
while(p!=NULL)
{
printf(“%s→%s ”,G.vertices[i].data,G.vertices[p->adjvex].data);
p=p->nextarc;
}
printf(“n”);
} } Status FindInDegree(ALGraph G,int indegree[]){
int i;
ArcNode *p;
for(i=0;i
indegree[i]=0;
for(i=0;i
{
p=G.vertices[i].firstarc;
while(p)
{
indegree[p->adjvex]++;
p=p->nextarc;
}
} } Status InitStack(SqStack *S){
(*S).base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
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=(SElemType *)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 numterm,int upterm){
ArcNode *p;
SqStack S;
int indegree[MAX_VERTEX_NUM];//存放各节点的入度
int i,j, k, m,n,q;
int count;//课程编排数目计数器
int sumcredit;//每个学期的课程学分累加器
FindInDegree(G, indegree);
for(i=0;i
G.vertices[i].indegree=indegree[i];
InitStack(&S);
count=0;
k=0;
while((count!=G.vexnum)&&(k
{
sumcredit=0;
q=0;
for(i=0;i
if((G.vertices[i].indegree==0)&&(G.vertices[i].state==NOTSTUDY))
{
Push(&S,i);
G.vertices[i].state=STUDY;//避免入度为零节点重复入栈
}
if(!StackEmpty(&S)&&(q
{
k= k+1;
printf(“第%d个学期学的课程:”,k);
printf(“n”);
while((!StackEmpty(&S))&&(q
{
Pop(&S,&j);
q=q+1;
sumcredit=sumcredit+G.vertices[j].credit;
printf(“%s ”,G.vertices[j].data);
count++;
for(p=G.vertices[j].firstarc;p;p=p->nextarc)//对j号顶点每个邻接点的入度减一
G.vertices[p->adjvex].indegree--;
}
printf(“学分为:n”);
printf(“%dn”,sumcredit);
}
}
return OK;} Status TopologicalSort1(ALGraph G,int numterm,int uplcredit){
ArcNode *p;
SqStack S;
int indegree[MAX_VERTEX_NUM];//存放各节点的入度
int i,j, k, m,n;
int count;//课程编排数目计数器
int sumcredit;//每个学期的课程学分累加器
FindInDegree(G, indegree);
for(i=0;i
G.vertices[i].indegree=indegree[i];
InitStack(&S);
count=0;
k=0;
while(count!=G.vexnum && k
{
sumcredit=0;
for(i=0;i
if((G.vertices[i].indegree==0)&&(G.vertices[i].state==NOTSTUDY))
{
Push(&S,i);
G.vertices[i].state = STUDY;//避免入度为零节点重复入栈
}
if(!StackEmpty(&S)&&(sumcredit
{
k= k+1;
printf(“n”);
printf(“第%d个学期学得课程有:n”,k);
sumcredit=0;
while((!StackEmpty(&S))&&(sumcredit
{
Pop(&S,&j);
sumcredit=sumcredit+G.vertices[j].credit;
if(sumcredit
{
printf(“%s ”,G.vertices[j].data);
count++;
for(p=G.vertices[j].firstarc;p;p=p->nextarc)//对j号顶点每个邻接点的入度减一
G.vertices[p->adjvex].indegree--;
}
else
{
Push(&S,j);//将未输出的节点重新压入栈
count--;
}
}
printf(“n学分为:n”);
printf(“%dn”,sumcredit);
}
}
if(count==G.vexnum)
printf(“编排成功”);
else printf(“编排不成功”);} int main(){
int x,y,z;
ALGraph G;
printf(“以下为教学计划编制问题的求解过程:n”);
printf(“请输入学期总数:”);
scanf(“%d”,&x);
printf(“每学期课程上限:”);
scanf(“%d”,&y);
printf(“输入学分上限:”);
scanf(“%d”,&z);
CreateGraph(G);
Display(G);
TopologicalSort1(G,x,z);}
背景大学的每个专业都要制定教学计划。假设任何专业都有固定的学习年限,每学年含两学期,每学期的时间长度和学分上限值均相等。每个专业开设的课程都是确定的,而且课程在开设时......
目 录1 课题需求描述 ..........................................2 1.1 教学计划编制问题 ..................................2 1.2 进制转换 ................................
源代码观后感......
《源代码》观后感我一直期待着看《源代码》这部悬疑剧,只因纯粹地喜欢心理剧跟心理战。本片主要讲述一列车爆炸引起伤亡无数,古德雯与博士为了解救列车上的数百名乘客,将已在一......
刀豆文库小编为你整合推荐6篇《源代码》观后感,也许这些就是您需要的文章,但愿刀豆文库能带给您一些学习、工作上的帮助。......