//判断无向图的关节点
#include
#include
#define Vnum
typedef struct arcnode
{
int adjvex;
struct arcnode *nextarc;
}arcnode;
typedef struct vexnode
{
int vertex;
arcnode *firstarc;
}adjlist[Vnum];
typedef struct graphs
{
adjlist adjlist;
int vexnumarcnum;
}graph;
void create(graph *g)
{
int neijk;
arcnode *p;
cout<<创建一个图:\t;
cout<<顶点数;
cin>>n;
cout<<\t\t边数;
cin>>e;
g>vexnum=n;
g>arcnum=e;
for(i=;i {
g->adjlist[i].vertex=i;
g->adjlist[i].firstarc=NULL;
}
for(k=0;k {
cout<<"第"< cin>>i>>j;
p=(arcnode *)malloc(sizeof(arcnode));
p->adjvex=j;
p->nextarc=g->adjlist[i].firstarc;
g->adjlist[i].firstarc=p;
}
}
void disp(graph *g)
{
int i,have;
arcnode *p;
cout<<"输出图:"< for(i=0;ivexnum;i++)
{
p=g->adjlist[i].firstarc;
have=0;
while(p!=NULL)
{
cout<<"("<adjvex<<")";
p=p->nextarc;
have=1;
}
if(have==1)
cout< }
}
void dfs(graph g,int v,int visited[])
{
arcnode *p;
cout< cin>>v;
cout<<"深度优先序列:";
dfs(g,v,visited);
cout< }
//有限期的作业排序
#include
#include "iomanip.h"
void JOB_S(int n,int *D);
void main()
{
int *D,*P; //定义变量数组,采用动态分配内存
int i,n;
cout<<"请输入要处理的作业数n:";
cin>>n;
D=new int[n+1]; //作业的截止期限数组
P=new int[n+1]; //作业的效益数组
cout<<"请输入作业i的期限值D(1-"< for(i=1;i<=n;i++) //按非增顺序输入
{
cout<<"作业"<
cin>>D[i];
}
cout< cout<<"请输入作业i的效益值P(1-"< for(i=1;i<=n;i++) //按非增顺序输入
{
cout<<"作业"<
cin>>P[i];
}
cout< JOB_S(n,D);
}
void JOB_S(int n,int *D)
{
int i,k,r;
int *J=new int[n+1];
k=1;
D[0]=0;
J[0]=0;
J[1]=1;
for(i=2;i<=n;i++)
{
r=k;
while(D[J[r]]>D[i] && D[J[r]]!=r)
r=r-1;
if(D[J[r]]<=D[i] && D[i]>r)
{
for(int x=k;x>=r+1;x--)
J[x+1]=J[x];
J[r+1]=i;
k++;
}
}
cout<<"该作业的最优处理顺序为:";
for(i=1;i<=k;i++)
cout< cout< }