Skip to content

Commit a567c20

Browse files
committed
list reverse
1 parent f77ebeb commit a567c20

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

oracle_sort/OracleSort.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,26 @@ public Node(Integer[] arr) {
4444
}*/
4545
} //Node
4646

47+
public void reverse() {
48+
Node prev = null;
49+
while(root != null) {
50+
Node rnext = root.next;
51+
root.next = prev;
52+
prev = root;
53+
root = rnext;
54+
}
55+
root = prev;
56+
} //reverse
57+
4758
//печать списка
4859
public void print() {
49-
root = this;
60+
Node r = root;
5061
while(root != null) {
5162
System.out.print(root.val + ", ");
5263
root = root.next;
5364
}
65+
root = r;
66+
System.out.println("");
5467
} //print
5568
}
5669

@@ -501,21 +514,31 @@ protected boolean isSortArr(Comparable[] arr) {
501514

502515
public static void main(String[] args) {
503516

504-
JUnitCore runner = new JUnitCore();
517+
/*JUnitCore runner = new JUnitCore();
505518
Result result = runner.run(OracleSortTest.class);
506519
System.out.println("run tests: " + result.getRunCount());
507520
System.out.println("failed tests: " + result.getFailureCount());
508521
System.out.println("ignored tests: " + result.getIgnoreCount());
509-
System.out.println("success: " + result.wasSuccessful());
522+
System.out.println("success: " + result.wasSuccessful());*/
510523

511-
/*Integer arr[] = {2, 6, 3, 5, 1, 7, 8, 0, 27, 17, 99, 13, 1, 7};
524+
Integer arr[] = {2, 6, 3, 5, 1, 7, 8, 0, 27, 17, 99, 13, 1, 7};
512525

513526
System.out.println(Arrays.toString(arr));
514527

528+
Node list = new Node(arr);
529+
list.print();
530+
list.print();
531+
System.out.println("reverse:");
532+
list.reverse();
533+
list.print();
534+
System.out.println("reverse:");
535+
list.reverse();
536+
list.print();
537+
515538
//Arrays.sort(arr);
516539
//Sorts.bubleSort(arr);
517540
//Sorts.insertSort(arr);
518-
Sorts.InsertSortList( new Node(arr) ).print();
541+
//Sorts.InsertSortList( new Node(arr) ).print();
519542

520543
//(new Tree(arr)).traverse();
521544

@@ -527,10 +550,10 @@ public static void main(String[] args) {
527550

528551
//new OracleSort(5, 2).sort(arr);
529552

530-
System.out.println(Arrays.toString(arr));
553+
//System.out.println(Arrays.toString(arr));
531554

532-
System.out.println("7=" + Sorts.binary_search(arr, 7));
533-
System.out.println("73=" + Sorts.binary_search(arr, 73));*/
555+
//System.out.println("7=" + Sorts.binary_search(arr, 7));
556+
//System.out.println("73=" + Sorts.binary_search(arr, 73));
534557
}
535558

536559
}

0 commit comments

Comments
 (0)