乱图乱画(不知道自己写的什么鬼)

#include <stdio.h>
#include <malloc.h>
#include <Windows.h>
#include <conio.h>
#include <queue>
#include <cstdlib>
#include <iostream>
using namespace std;
#define unmax 10000
#define White 0
#define Gray  1
#define Black 2
typedef struct point{
	int color ;
	int d ;
	struct point *pi ;
	int value ;
}*Ppoint;
typedef struct node{

	Ppoint key ;
	struct node *next ;
}*Pmap;

Pmap Create_Link(){
	Pmap H,L,P;
	int num ;
	H =  (Pmap)malloc(sizeof(struct node));
	H->key = (Ppoint)malloc(sizeof(struct point));
	P =  (Pmap)malloc(sizeof(struct node));
	P->key = (Ppoint)malloc(sizeof(struct point));
	
	if (!H)
	{
		printf("error\n");
	}

	H->next = NULL ;
	P = H ;
	scanf("%d",&num);
	while(num!=(-1)){
		
		L =  (Pmap)malloc(sizeof(struct node));
		L->key  = (Ppoint)malloc(sizeof(struct point));
		L -> key->value = num ;
		L->next = P->next ;
		P->next = L ;
		P = L ;
		scanf("%d",&num);
	}
	return H ;
}

void Out_Putlink(Pmap Ptr){
	if (!Ptr)
	{
		printf("output error\n");
		exit(0);
	}
	Pmap ptr = (Pmap)malloc(sizeof(struct node));
	ptr->key = (Ppoint)malloc(sizeof(struct point));
	ptr = Ptr->next ;
	while(ptr){
		printf("%d ",ptr->key->value);
		ptr = ptr->next ;
	}
	printf("\n");
}

void BFS(Pmap G[] , Ppoint s ,int n){
	Pmap u ;
	int i ;
	for (i =0 ; i < n ;i++)
	{
		u = G[i]->next;
		while(u){
			if (u->key!=s)
			{
				u->key->color = White ;
				u->key->d = unmax ;
				u->key->pi = NULL ;
			}
			u = u->next ;
		}
	}
	s->color = Gray ;
	s->d = 0;
	s->pi = NULL ;
	queue<Ppoint>Q ;
	Q.push(s);
	while(!Q.empty()){
		Ppoint x,v;
		x = Q.front(); 
		Q.pop();
		Pmap ptr ;
		int i ;
		for (i = 0 ; i< n ; i++)
		{
			if (G[i]->next->key == x)
			{
				ptr = G[i] ;
			}

		}		
		
		while(ptr->next){
			v = ptr->next->key;
			if (v->color==White)
			{
				v->color = Gray ;
				v->d++;
				v->pi = x ; 
			}
			Q.push(v);
		}
		x->color = Black ;
		ptr->next = ptr->next->next ;
	}
}

void Print_Path(Pmap G[],Ppoint s ,Ppoint v) {

	if (s==v)
		printf("%d",s->value);
	else if(v->pi==NULL)
		printf("no path\n");
	else
		Print_Path(G,s,v->pi);
	printf("%d",v->value);
}
int main(){
	Pmap Ptr[3] ;
	int i ;
	for (i=0 ; i < 3 ;i ++){
		Ptr[i] = (Pmap)malloc(sizeof(struct node));
		Ptr[i]->key =(Ppoint)malloc(sizeof(struct point));
		Ptr[i] = Create_Link();
	}
	Ppoint s ;
	//s->color=1;s->d=0;s->pi=NULL;s->value = 1;
	BFS(Ptr,s,3);
	for (i=0 ; i < 3 ;i ++)
		Out_Putlink(Ptr[i]);
	getch();
	return  0 ;
}
乱写一通,我要放弃这样的图的构造了。。。。表示累觉不爱
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值