-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph2.c
76 lines (58 loc) · 1.48 KB
/
graph2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// main.c
// AM2
//
// Created by 余彬 on 15/7/10.
// Copyright (c) 2015年 余彬. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
typedef struct Box{
int size;
char *VexTable;
int **VexsTable;
}Box,*pBox;
int Get(char *pVT,char c,int size){
int i;
for(i=0;i<=size;i++)
if(pVT[i]==c)
break;
if(pVT[i]==c)
return 1;
else return -1;
}
int Create(pBox pB){
int i,j;
char c,c1,c2;
pB->VexTable=(char *)malloc(sizeof(char));
pB->VexsTable=(int **)malloc(sizeof(int *)*(pB->size));
for(i=0;i<(pB->size);i++)
(pB->VexsTable)[i]=(int *)malloc(sizeof(int)*(pB->size));
printf("Please enter the vexs name(Like abc represent a,b,c vexs):\n");
scanf("%c",&c);
i=0;
while (c!='\n') {
(pB->VexTable)[i]=c;
i++;
scanf("%c",&c);
}
printf("Please enter the vexs relation(Like a,b c,d)type 2 times Space to finish!:\n");
scanf("%c,%c ",&c1,&c2);
while(c1!='\n'){
i=Get(pB->VexTable,c1,pB->size);
j=Get(pB->VexTable,c2,pB->size);
pB->VexsTable[i][j]=1;
pB->VexsTable[j][i]=1;
printf("Please enter the vexs relation(Like a,b c,d):\n");
scanf("%c,%c",&c1,&c2);
}
return 1;
}
int main(int argc, const char * argv[]) {
Box b;
printf("Please enter the size of vexs:\n");
scanf("%d",&(b.size));
getchar();
Create(&b);
return 0;
}