Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Snowleopard_wu
Java
提交
5ec13c6b
J
Java
项目概览
Snowleopard_wu
/
Java
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
Java
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
5ec13c6b
编写于
12月 08, 2019
作者:
Y
Yang Libin
提交者:
GitHub
12月 08, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1180 from myidrajkumar/Development
Fixing 'Generics' issue in Sort
上级
6ad2c9ff
56b374ce
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
26 addition
and
11 deletion
+26
-11
src/main/java/com/sorts/BubbleSort.java
src/main/java/com/sorts/BubbleSort.java
+2
-2
src/main/java/com/types/DataStructure.java
src/main/java/com/types/DataStructure.java
+1
-1
src/main/java/com/types/Sort.java
src/main/java/com/types/Sort.java
+2
-2
src/test/java/com/sorts/BubbleSortTest.java
src/test/java/com/sorts/BubbleSortTest.java
+21
-6
未找到文件。
src/main/java/com/sorts/BubbleSort.java
浏览文件 @
5ec13c6b
...
...
@@ -2,7 +2,7 @@ package com.sorts;
import
com.types.Sort
;
public
class
BubbleSort
<
T
>
implements
Sort
<
T
>
{
public
class
BubbleSort
<
T
extends
Comparable
<
T
>
>
implements
Sort
<
T
>
{
/**
* This method implements the Generic Bubble Sort
*
...
...
@@ -11,7 +11,7 @@ public class BubbleSort<T> implements Sort<T> {
**/
@Override
public
<
T
extends
Comparable
<
T
>>
T
[]
sort
(
T
[]
array
)
{
public
T
[]
sort
(
T
[]
array
)
{
int
last
=
array
.
length
;
//Sorting
boolean
swap
;
...
...
src/main/java/com/types/DataStructure.java
浏览文件 @
5ec13c6b
...
...
@@ -3,7 +3,7 @@ package com.types;
import
java.util.Iterator
;
/**
* This interface is to define ba
cis
functionality expected out of any implementation class
* This interface is to define ba
sic
functionality expected out of any implementation class
* Since this is a data structure it should have the flexibility to contain any kind of object hence it has been made generic
* Any implementation class need not to be thread safe or it could be depending on the implementation class how does it want to behave.
*
...
...
src/main/java/com/types/Sort.java
浏览文件 @
5ec13c6b
package
com.types
;
@FunctionalInterface
public
interface
Sort
<
T
>
{
public
interface
Sort
<
T
extends
Comparable
<
T
>
>
{
<
T
extends
Comparable
<
T
>>
T
[]
sort
(
T
[]
array
);
T
[]
sort
(
T
[]
array
);
}
src/test/java/com/sorts/BubbleSortTest.java
浏览文件 @
5ec13c6b
...
...
@@ -6,17 +6,32 @@ import org.junit.jupiter.api.Test;
class
BubbleSortTest
{
@Test
void
bubbleSortTest
()
{
BubbleSort
bubbleSort
=
new
BubbleSort
();
void
bubbleSortTest
Integers
()
{
BubbleSort
<
Integer
>
bubbleSort
=
new
BubbleSort
<>
();
Integer
[]
unsortedInt
=
new
Integer
[]
{
0
,
5
,
9
,
2
,
1
,
3
,
4
,
8
,
6
,
7
};
Integer
[]
sortedInt
=
new
Integer
[]
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
Integer
[]
unsortedInt
=
{
0
,
5
,
9
,
2
,
1
,
3
,
4
,
8
,
6
,
7
};
Integer
[]
sortedInt
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
Assertions
.
assertArrayEquals
(
sortedInt
,
bubbleSort
.
sort
(
unsortedInt
));
Character
[]
unsortedChar
=
new
Character
[]{
'f'
,
'h'
,
'c'
,
'a'
,
'b'
,
'd'
,
'g'
,
'e'
};
Character
[]
sortedChar
=
new
Character
[]{
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
};
}
@Test
void
bubbleSortTestCharacters
()
{
BubbleSort
<
Character
>
bubbleSort
=
new
BubbleSort
<>();
Character
[]
unsortedChar
=
{
'f'
,
'h'
,
'c'
,
'a'
,
'b'
,
'd'
,
'g'
,
'e'
};
Character
[]
sortedChar
=
{
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
,
'g'
,
'h'
};
Assertions
.
assertArrayEquals
(
sortedChar
,
bubbleSort
.
sort
(
unsortedChar
));
}
@Test
void
bubbleSortTestStrings
()
{
BubbleSort
<
String
>
bubbleSort
=
new
BubbleSort
<>();
String
[]
unsortedChar
=
{
"abc"
,
"adc"
,
"bcd"
,
"abb"
,
"abc"
,
"acb"
};
String
[]
sortedChar
=
{
"abb"
,
"abc"
,
"abc"
,
"acb"
,
"adc"
,
"bcd"
};
Assertions
.
assertArrayEquals
(
sortedChar
,
bubbleSort
.
sort
(
unsortedChar
));
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录