Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yin-zh
sorting-algorithm-course-config
提交
58759f66
S
sorting-algorithm-course-config
项目概览
yin-zh
/
sorting-algorithm-course-config
通知
6
Star
0
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
14
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
S
sorting-algorithm-course-config
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
14
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
58759f66
编写于
8月 26, 2021
作者:
yin-zh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test
上级
c717bb9f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
21 deletion
+9
-21
06_快速排序/answer.md
06_快速排序/answer.md
+4
-20
10_数组算法题_旋转数组/answer.md
10_数组算法题_旋转数组/answer.md
+2
-1
14_栈和队列算法题_用两个栈实现队列/answer.md
14_栈和队列算法题_用两个栈实现队列/answer.md
+3
-0
未找到文件。
06_快速排序/answer.md
浏览文件 @
58759f66
...
@@ -5,13 +5,7 @@ package com.yzh;
...
@@ -5,13 +5,7 @@ package com.yzh;
public
class
QuickSort
{
public
class
QuickSort
{
/**
//快速排序方法
* 快速排序方法
* @param array
* @param start
* @param end
* @return
*/
public
int
[]
solution
(
int
[]
array
,
int
start
,
int
end
)
{
public
int
[]
solution
(
int
[]
array
,
int
start
,
int
end
)
{
if
(
array
.
length
<
1
||
start
<
0
||
end
>=
array
.
length
||
start
>
end
)
{
if
(
array
.
length
<
1
||
start
<
0
||
end
>=
array
.
length
||
start
>
end
)
{
return
null
;
return
null
;
...
@@ -26,13 +20,8 @@ public class QuickSort {
...
@@ -26,13 +20,8 @@ public class QuickSort {
return
array
;
return
array
;
}
}
/**
* 快速排序算法——partition
//快速排序算法
* @param array
* @param start
* @param end
* @return
*/
public
int
partition
(
int
[]
array
,
int
start
,
int
end
)
{
public
int
partition
(
int
[]
array
,
int
start
,
int
end
)
{
int
pivot
=
(
int
)
(
start
+
Math
.
random
()
*
(
end
-
start
+
1
));
int
pivot
=
(
int
)
(
start
+
Math
.
random
()
*
(
end
-
start
+
1
));
int
smallIndex
=
start
-
1
;
int
smallIndex
=
start
-
1
;
...
@@ -48,12 +37,7 @@ public class QuickSort {
...
@@ -48,12 +37,7 @@ public class QuickSort {
return
smallIndex
;
return
smallIndex
;
}
}
/**
//交换数组内两个元素
* 交换数组内两个元素
* @param array
* @param i
* @param j
*/
public
void
swap
(
int
[]
array
,
int
i
,
int
j
)
{
public
void
swap
(
int
[]
array
,
int
i
,
int
j
)
{
int
temp
=
array
[
i
];
int
temp
=
array
[
i
];
array
[
i
]
=
array
[
j
];
array
[
i
]
=
array
[
j
];
...
...
10_数组算法题_旋转数组/answer.md
浏览文件 @
58759f66
...
@@ -11,7 +11,8 @@ public class RotateArray {
...
@@ -11,7 +11,8 @@ public class RotateArray {
reverse
(
nums
,
k
,
nums
.
length
-
1
);
reverse
(
nums
,
k
,
nums
.
length
-
1
);
return
nums
;
return
nums
;
}
}
//数组翻转函数:对数组的指定部分进行翻转
public
void
reverse
(
int
[]
nums
,
int
start
,
int
end
)
{
public
void
reverse
(
int
[]
nums
,
int
start
,
int
end
)
{
while
(
start
<
end
)
{
while
(
start
<
end
)
{
int
temp
=
nums
[
start
];
int
temp
=
nums
[
start
];
...
...
14_栈和队列算法题_用两个栈实现队列/answer.md
浏览文件 @
58759f66
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
package
com.yzh
;
package
com.yzh
;
public
class
CQueue
{
public
class
CQueue
{
//初始化两个栈
Deque
<
Integer
>
stack1
;
Deque
<
Integer
>
stack1
;
Deque
<
Integer
>
stack2
;
Deque
<
Integer
>
stack2
;
...
@@ -12,10 +13,12 @@ public class CQueue {
...
@@ -12,10 +13,12 @@ public class CQueue {
stack2
=
new
LinkedList
<
Integer
>();
stack2
=
new
LinkedList
<
Integer
>();
}
}
//插入元素
public
void
appendTail
(
int
value
)
{
public
void
appendTail
(
int
value
)
{
stack1
.
push
(
value
);
stack1
.
push
(
value
);
}
}
//删除元素
public
int
deleteHead
()
{
public
int
deleteHead
()
{
if
(
stack2
.
isEmpty
())
{
if
(
stack2
.
isEmpty
())
{
while
(!
stack1
.
isEmpty
())
{
while
(!
stack1
.
isEmpty
())
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录