-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_Select_Sort
More file actions
99 lines (94 loc) · 1.43 KB
/
Bubble_Select_Sort
File metadata and controls
99 lines (94 loc) · 1.43 KB
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
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//冒泡排序
void Bubble_Sort(char* p, int len)
{
int i, j;
for (i = 0; i < len; i++)
{
for (j = 0; j < len - i - 1; j++)
{
if (*(p + j) < *(p + j + 1))
{
int temp = *(p + j);
*(p + j) = *(p + j + 1);
*(p + j + 1) = temp;
}
}
}
}
//选择排序
void Select_Sort(char p[], int len)
{
int i, j, pos;
for (i = 0; i < len - 1; i++)
{
pos = i;
for (j = i + 1; j < len; j++)
{
if (p[j] < p[pos]) //改指针形式,*(p+j) < *(p+pos)
{
pos = j;
}
}
if (pos != i)
{
int temp = p[i];
p[i] = p[pos];
p[pos] = temp;
}
}
}
void input(char* p, int len)
{
printf("输入%d个数: ", len);
for (int i = 0; i < len; i++)
{
scanf_s(" %d", p + i);
}
printf("输入ok!\n");
}
void output(char* p, int len)
{
printf("输出%d个数: ", len);
for (int i = 0; i < len; i++)
{
printf("%d ", *(p + i));
}
printf("\n输出ok!\n");
}
//快速排序
//单例模式
class singleton
{
private:
singleton() {}
static singleton* Instance;
public:
static singleton* GetInstance()
{
if (Instance == NULL)
{
//Lock
if (Instance == NULL)
{
Instance = new singleton();
}
//UNLock
}
return Instance;
//static singleton Instance;
//return &Instance;
}
};
int main(void)
{
//选择排序
char ch1[20] = { '\0' };
input(ch1, 10);
Select_Sort(ch1, 10);
output(ch1, 10);
}