-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhierarchical_new.c
78 lines (76 loc) · 1.28 KB
/
hierarchical_new.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
77
78
#include<stdio.h>
#include<stdlib.h>
struct node
{
char N[25];
int df;
struct node *pc;
struct node *ps;
};
struct node * A[20];
int in=0, c=0;
struct node * create(struct node *P, int N)
{
int i;
struct node *Tmp, *T;
Tmp=P;
for(i=0;i<N;i++)
{
T=(struct node *)malloc(sizeof(struct node));
printf("Enter name : ");
scanf("%s", T->N);
printf("Enter dir(1) or file(0): ");
scanf("%d", &T->df);
if(T->df==1)
{
A[c]=T;
c++;
}
T->pc=NULL;
T->ps=NULL;
if(i==0)
{
Tmp->pc=T;
Tmp=T;
}
else
{
Tmp->ps=T;
Tmp=T;
}
}
}
void display(struct node *P)
{
int i;
P=P->pc;
do
{
printf("\n%s(%d)",P->N, P->df);
if(P->df==1 && P->pc!=NULL)
display(P);
P=P->ps;
}while(P!=NULL);
}
int main()
{
int nu,nc;
int i,j,k;
struct node *Hdr;
Hdr =(struct node *)malloc(sizeof(struct node));
Hdr->df=1;
Hdr->pc=NULL;
Hdr->ps=NULL;
printf("\nEnter number of users :\n ");
scanf("%d",&nu);
create(Hdr, nu);
for(in=0;in<c;in++)
{
printf("\nEnter number of child nodes for %s : ", A[in]->N);
scanf("%d", &nc);
create(A[in], nc);
}
printf("\n Hierarchical\n");
display(Hdr);
return 0;
}