-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.c
88 lines (83 loc) · 1.83 KB
/
sort.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
#pragma warning(disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "my_struct.h"
#include "my_define.h"
#include "my_func.h"
void phonebook_sort(TEL **pst, int *cnt)
{
int choice;
if (*cnt == 0) // 저장되어있는 값이 없으면 경고 출력
printf("NO MEMBER\n");
else
{
printf("*****Menu*****\n");
printf("<1.SortByName><2.SortByBirth>\n");
printf("Enter_the_menu_number:");
scanf("%d", &choice);
switch (choice)
{
case 1: sortbyname(pst, cnt); break; // SortByName
case 2: sortbybirth(pst, cnt); break; // SortByBirth
}
}
}
void sortbyname(TEL **pst, int *cnt) // 전체 자료를 이름순으로 버블정렬
{
TEL *tmp;
int i, j;
for (i = 0; i < *cnt - 1; i++)
{
for (j = 0; j < *cnt - 1 - i; j++)
{
if (strcmp((*(pst + j))->name, (*(pst + j + 1))->name) > 0)
{
tmp = *(pst + j);
*(pst + j) = *(pst + j + 1);
*(pst + j + 1) = tmp;
}
}
}
}
void sortbybirth(TEL **pst, int *cnt) // 전체 자료를 생일순으로 버블정렬
{
TEL *tmp;
int i, j;
for (i = 0; i < *cnt - 1; i++) // 전체 자료를 일순으로 정렬
{
for (j = 0; j < *cnt - 1 - i; j++)
{
if (atoi((*(pst + j))->birth) % 100 < atoi((*(pst + j + 1))->birth) % 100)
{
tmp = *(pst + j);
*(pst + j) = *(pst + j + 1);
*(pst + j + 1) = tmp;
}
}
}
for (i = 0; i < *cnt - 1; i++) // 전체 자료를 달순으로 정렬
{
for (j = 0; j < *cnt - 1 - i; j++)
{
if ((atoi((*(pst + j))->birth) % 10000) / 100 < (atoi((*(pst + j + 1))->birth) % 10000) / 100)
{
tmp = *(pst + j);
*(pst + j) = *(pst + j + 1);
*(pst + j + 1) = tmp;
}
}
}
for (i = 0; i < *cnt - 1; i++) // 전체 자료를 년순으로 정렬
{
for (j = 0; j < *cnt - 1 - i; j++)
{
if (atoi((*(pst + j))->birth) / 10000 < atoi((*(pst + j + 1))->birth) / 10000)
{
tmp = *(pst + j);
*(pst + j) = *(pst + j + 1);
*(pst + j + 1) = tmp;
}
}
}
}