#include
#include
typedef char BTDataType;
typedef struct BiTreeNode
{
struct BTreeNode* left;
struct BTreeNode* right;
BTDataType data;
}BTNode;
typedef struct person_information
{
char name[20];
int age;
char job[20];
char friends[20];
}temp, person[10];
BTNode* CreateBTreeNode(BTDataType x)
{
BTNode* node = (BTNode*)malloc(sizeof(BTNode));
node->data = x;
node->left = NULL;
node->right = NULL;
return node;
}
int find(int x)
{
if(x == a[x])
return a[x];
a[x] = find(a[x]);
return a[x];
}
int a[300];
int main()
{
int i,j,n,index;
scanf("%d",&n);
for(i=0;iscanf("%s%d%s", person[i].name, &person[i].age, person[i].job,person[i].friends);
for(i=0;ifor(j=i+1;jif(person[index].age>person[j].age)
index=j;
temp=person[index];
person[index]=person[i];
person[i]=temp;
}
for(i=0;iprintf("%s %ld %s\n", person[i].name,person[i].age,person[i].job,person[i].friends));
int N;
scanf("%d\n", &N);
char graph_1[N+1][N+1];
for(int i=0;iscanf("%s",graph_1[i]);
}
int graph_2[N][N];
for(int i = 0;i < N;i++)
for(int j = 0;j < N;j++)
{
graph_2[i][j] = graph_1[i][j]-'0';
if(graph_2[i][j] == 1)
{
if(find(i) != find(j))
a[find(i)] = find(j);
}
}
for(int i = 0;i < N;i++)
for(int j = 0;j < N;j++)
if(find(i) == find(j))
graph_2[i][j] = 1;
for(int i = 0;i < N;i++)
for(int j = 0;j < N;j++)
printf("%d",graph_2[i][j]);
printf("\n");
}
return 0;
}
社交圈通讯录,包括姓名、年龄、职业和好友然后,只要你是对方的好友,就会根据推送给我的好友,林a的好友是陈b,陈b的好友是黄c,那么林a就会和黄c成为好友,根据姓的拼音首字母的大小所在的位置实现二叉排序树的构建和查找,并且在这个社交圈通讯录中的完全子图里面每两个用户都互为好友。
已经创立二叉树了,这个图怎么用个人数据结构怎么输入到二叉树里区查找,又要实现推荐算法,请帮忙完善一下
1 int equal(tree t1,tree t2)
2 {
3 int k;
4 if(t1==NULL&&t2==NULL)
5 return TRUE;
6 else if(t1!=NULL&&t2==NULL||t1==NULL&&t2!=NULL)
7 {
8 return FALSE;
9 }
10 else if(t1->data!=t2->data)
11 {
12 return FALSE;
13 }
14 for(k=0;k<m;k++)
15 {
16 equal(t1->child[k],t2->child[k]);
17 if(equal(t1->child[k],t2->child[k])==FALSE)
18 {
19 return FALSE;
20 }
21 else
22 return TRUE;
23 }
24 }
1 void preorder1(bintree t)
2 {
3 seqstack s;
4 init(&s);
5 while(t||!empty(&s))
6 {
7 if(t)
8 {
9 printf("%c",t->data);
10 push(&s,t);
11 t=t->lchild;
12 }
13 else if(!empty(&s))
14 {
15 t=pop(&s);
16 t=t->rchild;
17 }
18 }
3)编写算法函数degree(LinkedGraph g)输出以邻接表为存储结构的无向图的各顶点的度。
1 void degree(LinkedGraph g)
2 {
3 int k;
4 int n;
5 EdgeNode *p;
6 for(k=0;k<g.n;k++)
7 {
8 p=g.adjlist[k].FirstEdge;
9 n=0;
10 while(p!=NULL)
11 {
12 n++;
13 p=p->next;
14 }
15 if(k==0)
16 {
17 printf("%d\n",n);
18 }
19 else
20 {
21 printf("%d\n",n);
22 }
23 }
24 }