-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
71 lines (65 loc) · 2.65 KB
/
Main.java
File metadata and controls
71 lines (65 loc) · 2.65 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
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
File file = new File("numere.txt");
if(!file.exists()) {
try {
file.createNewFile();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
ArrayList<Integer> list = new ArrayList<Integer>();
try {
Scanner scanner = new Scanner(new File("numere.txt"));
while (scanner.hasNextInt()) {
list.add(scanner.nextInt());
}
scanner.close();
} catch (FileNotFoundException e) {
System.out.println("Fisierul nu a fost gasit.");
return;
}
// afisarea listei initiale
System.out.println("Lista initiala:");
for (int i = 0; i < list.size(); i++) {
System.out.print(list.get(i) + " ");
}
System.out.println();
System.out.println("Numere in lista:" +list.size());
System.out.println();
// sortarea listei folosind fiecare metoda de sortare si afisarea rezultatelor
System.out.println();System.out.println();
System.out.println("Sortarea folosind Bubblesort:");
SortMethods.bubbleSort(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind Selection sort:");
SortMethods.selectionSort(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind Insertion sort:");
SortMethods.insertionSort(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind radix sort:");
SortMethods.radixSort(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind counting sort:");
SortMethods.countingSort(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind shaker sort:");
SortMethods.shakerSort(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind shell sort:");
SortMethods.shellSort(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind merge sort:");
SortMethods.test(new ArrayList<Integer>(list));
System.out.println();System.out.println();
System.out.println("Sortarea folosind quick sort:");
SortMethods.test2(new ArrayList<Integer>(list));
}
}