-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.c
68 lines (61 loc) · 1.04 KB
/
common.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
/*
* @Description:
* @LastEditors: hsjfans
* @Email: [email protected]
* @Date: 2019-02-28 19:50:08
* @LastEditTime: 2019-05-14 20:59:01
*/
#include <string.h>
#include "include/common.h"
/**
* @description: comparable
* @param {type}
* @return: 1 or 0
*/
int common_cmp_str(const Element key1, const Element key2)
{
return strcmp(key1, key2);
}
/**
* @description: compara the address of key1 and key2 pointer
* @param {type}
* @return: -1 if key1 less than key2;
* 0 if key1 == key2 ;
* 1 if key1 > key2;
*
*/
int common_cmp_ptr(const Element key1, const Element key2)
{
if (key1 < key2)
{
return -1;
}
else if (key1 > key2)
{
return 1;
}
else
{
return 0;
}
}
/**
* @description: swap two element
* @param {type}
* @return:
*/
void swap(Element *e1, Element *e2)
{
Element e;
e = *e1;
*e1 = *e2;
*e2 = e;
}
int max(int a, int b)
{
return a > b ? a : b;
}
int min(int a, int b)
{
return a > b ? b : a;
}