Skip to content

Commit c115f0c

Browse files
committed
Merge branch 'master' of https://github.com/byhieg/JavaTutorial
2 parents c7e8bbb + 212ff13 commit c115f0c

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/main/java/cn/byhieg/algorithmtutorial/Sort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ public int partition(int[] nums, int low, int high) {
169169
int x = nums[i];
170170
while (i < j) {
171171
//从右向左找到nums[j]小于x的元素
172-
while (i < j && nums[j] > x) j--;
172+
while (i < j && nums[j] >= x) j--;
173173
if (i < j) {
174174
nums[i] = nums[j];
175175
i++;
176176
}
177177

178178
//从左向右找到nums[i]大于x的元素
179-
while (i < j && nums[i] < x) i++;
179+
while (i < j && nums[i] <= x) i++;
180180
if (i < j) {
181181
nums[j] = nums[i];
182182
j--;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cn.byhieg.niotutorial;
2+
3+
import java.io.File;
4+
import java.io.FileNotFoundException;
5+
import java.io.IOException;
6+
import java.io.RandomAccessFile;
7+
import java.nio.ByteBuffer;
8+
import java.nio.channels.FileChannel;
9+
10+
/**
11+
* Created by shiqifeng on 2017/4/10.
12+
13+
*/
14+
public class NioTest {
15+
16+
public static void main(String[] args) throws IOException {
17+
String s = File.separator;
18+
RandomAccessFile aFile = new RandomAccessFile("D:" + s + "read_file.txt","rw");
19+
FileChannel inChannel = aFile.getChannel();
20+
21+
ByteBuffer buf = ByteBuffer.allocate(48);
22+
int bytesRead = inChannel.read(buf);
23+
while (bytesRead != -1) {
24+
buf.flip();
25+
while (buf.hasRemaining()) {
26+
System.out.print((char) buf.get());
27+
}
28+
29+
buf.clear();
30+
bytesRead = inChannel.read(buf);
31+
}
32+
33+
aFile.close();
34+
}
35+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
I don't know what I do now is right, those are wrong, and when I finally die then I know these.
2+
So what I can do now is to try to do everything well, and then wait to die .
3+
Sometimes I can be very happy to talk to everyone, can be very presumptuous, but no one knows,
4+
it is but very deliberately camouflage, camouflage; I can make him very happy very happy,
5+
but couldn't find the source of happiness, just giggle.

0 commit comments

Comments
 (0)