-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash groups.c
141 lines (136 loc) · 2.73 KB
/
hash groups.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include<stdio.h>
struct snode
{
char name[15];
struct snode* next;
};
typedef struct snode* student;
student shead;
struct gnode
{
char sports[10];
int nostd;
struct snode* link;
};
typedef struct gnode* group;
group sprtgrps[10];
group ghead;
group createnode()
{
group temp=malloc(sizeof(struct gnode));
printf("\nEnter the name of the sports :");
scanf("%s",&temp->sports);
temp->link=NULL;
}
void insert_student(int p)
{
int i,n;
printf("\nEnter the number of students:");
scanf("%d",&n);
sprtgrps[p]->nostd=n;
for(i=0;i<n;i++)
{
student temp=malloc(sizeof(struct snode));
printf("\nEnter the name of the student :");
scanf("%s",&temp->name);
temp->next=NULL;
if(sprtgrps[p]->link==NULL)
{
sprtgrps[p]->link=temp;
}
else
{
temp->next=sprtgrps[p]->link;
sprtgrps[p]->link=temp;
}
}
}
printdetail(int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\nFor sports %s",sprtgrps[i]->sports);
print(sprtgrps[i]->link);
}
}
print(group root)
{
student temp=root;
if(temp==NULL)
{
printf("\nThe list is empty!!\n\n");
return;
}
// printf("\nThe list of books are ");
printf("\nThe students are \n\n");
int i=1;
while(temp!=NULL)
{
printf("%d) %s\n",i,temp->name);
temp=temp->next;
i++;
}
printf("\n");
}
void insert(char* name,int p)
{
int i=0;
student temp=malloc(sizeof(struct snode));
//temp->name
strcpy(temp->name,name);
temp->next=NULL;
if(sprtgrps[p]->link==NULL)
{
sprtgrps[p]->link=temp;
return;
}
else
{
temp->next=sprtgrps[p]->link;
sprtgrps[p]->link=temp;
}
}
void main()
{
ghead=NULL;
shead=NULL;
int i,n;
printf("\nEnter the number of groups :");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nFor sports %d",i+1);
sprtgrps[i]=createnode();
}
printdetail(n);
int number;
printf("\nEnter the number of students :");
scanf("%d",&number);
char name1[10];
int a,b=0,c;
//printf("\nNo of students %d",number);
for(i=0;i<number;i++)
{
printf("\nEnter the name of the student %d :",i+1);
scanf("%s",&name1);
for(a=0;name1[a]!='\0';a++)
{
b=b+name1[a];
}
c=b%n;
// printf("\n%d grp->%d nogrps->%d",b,c,n);
printf("\nInserted into the group %s\n",sprtgrps[c]->sports);
insert(name1,c);
//printf("\nThe value of numer=%d and i=%d ",number,i);
}
/*
for(i=0;i<n;i++)
{
printf("\nFor sport %s",sprtgrps[i]->sports);
insert_student(i);
}
*/
printf("\nSTUDENT NAMES BASED ON THE GROUPS\n");
printdetail(n);
}