-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsort-student.c
111 lines (77 loc) · 1.94 KB
/
sort-student.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
/*
* C
* @project Exemplo
* @package main
* @author @jeffotoni
* @size 30/10/2017
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Struc Student
struct Student {
int registry;
char name[40];
};
// ordered by student record
void insertSortregistry(struct Student *pupil, int size)
{
int i, j;
struct Student aux;
for(i = 1; i < size; i++)
{
aux = pupil[i];
for(j=i; (j>0) && (aux.registry < pupil[j-1].registry); j-- )
{
pupil[j] = pupil[j - 1];
}
pupil[j] = aux;
}
}
// ordered by student name
void insertSortname(struct Student *pupil, int size)
{
int i, j;
struct Student aux;
for(i = 1; i < size; i++)
{
aux = pupil[i];
for(j=i; (j>0) && (strcmp(aux.name, pupil[j-1].name) < 0); j-- )
{
pupil[j] = pupil[j - 1];
}
pupil[j] = aux;
}
}
// start main
int main(){
int size = 2;
// defindo vetor 6 pupil
struct Student pupil[size];
for(int count = 0 ; count < size; count++)
{
fflush(stdin);
printf("\nStudent's name %d: ", count+1);
scanf("%s",pupil[count].name);
printf("\nStudent record : ");
scanf("%d", &pupil[count].registry);
}
insertSortregistry(pupil, size);
printf("\n################ listing order by enrollment ##################\n");
for(int count = 0 ; count < size ; count++)
{
printf("\nregistry: %.2d\n", pupil[count].registry);
// printf("\nAluno %d\n", count+1);
printf("name: %s\n",pupil[count].name);
}
insertSortname(pupil, size);
printf("\n################## listing order by name ####################\n");
for(int count = 0 ; count < size ; count++)
{
printf("\nStudent record : %.2d\n", pupil[count].registry);
// printf("\nAluno %d\n", count+1);
printf("Student's name: %s\n",pupil[count].name);
}
exit(0);
}