Skip to content

Commit 86d1ce1

Browse files
committed
init commit
1 parent 2aa05b4 commit 86d1ce1

File tree

137 files changed

+12985
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+12985
-0
lines changed

.gitignore

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,85 @@
2121

2222
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2323
hs_err_pid*
24+
25+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
26+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
27+
28+
# User-specific stuff
29+
.idea/**/workspace.xml
30+
.idea/**/tasks.xml
31+
.idea/**/usage.statistics.xml
32+
.idea/**/dictionaries
33+
.idea/**/shelf
34+
35+
# Generated files
36+
.idea/**/contentModel.xml
37+
38+
# Sensitive or high-churn files
39+
.idea/*
40+
41+
# Gradle
42+
.idea/**/gradle.xml
43+
.idea/**/libraries
44+
45+
# Gradle and Maven with auto-import
46+
# When using Gradle or Maven with auto-import, you should exclude module files,
47+
# since they will be recreated, and may cause churn. Uncomment if using
48+
# auto-import.
49+
# .idea/artifacts
50+
# .idea/compiler.xml
51+
# .idea/jarRepositories.xml
52+
# .idea/modules.xml
53+
# .idea/*.iml
54+
# .idea/modules
55+
# *.iml
56+
# *.ipr
57+
58+
# CMake
59+
cmake-build-*/
60+
61+
# Mongo Explorer plugin
62+
.idea/**/mongoSettings.xml
63+
64+
# File-based project format
65+
*.iws
66+
67+
# IntelliJ
68+
out/
69+
70+
# mpeltonen/sbt-idea plugin
71+
.idea_modules/
72+
73+
# JIRA plugin
74+
atlassian-ide-plugin.xml
75+
76+
# Cursive Clojure plugin
77+
.idea/replstate.xml
78+
79+
# Crashlytics plugin (for Android Studio and IntelliJ)
80+
com_crashlytics_export_strings.xml
81+
crashlytics.properties
82+
crashlytics-build.properties
83+
fabric.properties
84+
85+
# Editor-based Rest Client
86+
.idea/httpRequests
87+
88+
# Android studio 3.1+ serialized cache file
89+
.idea/caches/build_file_checksums.ser
90+
91+
.gradle
92+
**/build/
93+
!src/**/build/
94+
95+
# Ignore Gradle GUI config
96+
gradle-app.setting
97+
98+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
99+
!gradle-wrapper.jar
100+
101+
# Cache of project
102+
.gradletasknamecache
103+
104+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
105+
# gradle/wrapper/gradle-wrapper.properties

Examples/build.gradle

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
plugins {
2+
id 'java'
3+
}
4+
5+
group 'at.candir.examples'
6+
version '1.0-SNAPSHOT'
7+
8+
sourceCompatibility = 1.8
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
implementation project(':Library')
16+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2014, Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
3+
*
4+
* Developed for use with the book:
5+
*
6+
* Data Structures and Algorithms in Java, Sixth Edition
7+
* Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser
8+
* John Wiley & Sons, 2014
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
package examples.datastructure.arrays;
24+
25+
/**
26+
* Class for doing encryption and decryption using the Caesar Cipher.
27+
*/
28+
public class CaesarCipher {
29+
protected char[] encoder = new char[26]; // Encryption array
30+
protected char[] decoder = new char[26]; // Decryption array
31+
32+
/**
33+
* Constructor that initializes the encryption and decryption arrays
34+
*/
35+
public CaesarCipher(int rotation) {
36+
for (int k = 0; k < 26; k++) {
37+
encoder[k] = (char) ('A' + (k + rotation) % 26);
38+
decoder[k] = (char) ('A' + (k - rotation + 26) % 26);
39+
}
40+
}
41+
42+
/**
43+
* Returns String representing encrypted message.
44+
*/
45+
public String encrypt(String message) {
46+
return transform(message, encoder); // use encoder array
47+
}
48+
49+
/**
50+
* Returns decrypted message given encrypted secret.
51+
*/
52+
public String decrypt(String secret) {
53+
return transform(secret, decoder); // use decoder array
54+
}
55+
56+
/**
57+
* Returns transformation of original String using given code.
58+
*/
59+
private String transform(String original, char[] code) {
60+
char[] msg = original.toCharArray();
61+
for (int k = 0; k < msg.length; k++)
62+
if (Character.isUpperCase(msg[k])) { // we have a letter to change
63+
int j = msg[k] - 'A'; // will be value from 0 to 25
64+
msg[k] = code[j]; // replace the character
65+
}
66+
return new String(msg);
67+
}
68+
69+
/**
70+
* Simple main method for testing the Caesar cipher
71+
*/
72+
public static void main(String[] args) {
73+
CaesarCipher cipher = new CaesarCipher(3);
74+
System.out.println("Encryption code = " + new String(cipher.encoder));
75+
System.out.println("Decryption code = " + new String(cipher.decoder));
76+
String message = "THE EAGLE IS IN PLAY; MEET AT JOE'S.";
77+
String coded = cipher.encrypt(message);
78+
System.out.println("Secret: " + coded);
79+
String answer = cipher.decrypt(coded);
80+
System.out.println("Message: " + answer); // should be plaintext again
81+
}
82+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2014, Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
3+
*
4+
* Developed for use with the book:
5+
*
6+
* Data Structures and Algorithms in Java, Sixth Edition
7+
* Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser
8+
* John Wiley & Sons, 2014
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
package examples.datastructure.arrays;
24+
25+
import java.util.Arrays;
26+
27+
public class DeepClone {
28+
29+
public static int[][] deepClone(int[][] original) {
30+
int[][] backup = new int[original.length][]; // create top-level array of arrays
31+
for (int k = 0; k < original.length; k++)
32+
backup[k] = original[k].clone(); // copy row k
33+
return backup;
34+
}
35+
36+
public static void main(String[] args) {
37+
int[][] sample = {{1, 2, 3}, {4, 5, 6}};
38+
int[][] backup = deepClone(sample);
39+
40+
System.out.println("Sample:");
41+
System.out.println(Arrays.deepToString(sample));
42+
System.out.println("Backup:");
43+
System.out.println(Arrays.deepToString(backup));
44+
45+
for (int j = 0; j < sample.length; j++)
46+
for (int k = 0; k < sample[j].length; k++)
47+
sample[j][k] *= 10;
48+
49+
System.out.println("Sample:");
50+
System.out.println(Arrays.deepToString(sample));
51+
System.out.println("Backup:");
52+
System.out.println(Arrays.deepToString(backup));
53+
54+
}
55+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2014, Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
3+
*
4+
* Developed for use with the book:
5+
*
6+
* Data Structures and Algorithms in Java, Sixth Edition
7+
* Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser
8+
* John Wiley & Sons, 2014
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
package examples.datastructure.arrays;
24+
25+
public class GameEntry {
26+
private String name; // name of the person earning this score
27+
private int score; // the score value
28+
29+
/**
30+
* Constructs a game entry with given parameters..
31+
*/
32+
public GameEntry(String n, int s) {
33+
name = n;
34+
score = s;
35+
}
36+
37+
/**
38+
* Returns the name field.
39+
*/
40+
public String getName() {
41+
return name;
42+
}
43+
44+
/**
45+
* Returns the score field.
46+
*/
47+
public int getScore() {
48+
return score;
49+
}
50+
51+
/**
52+
* Returns a string representation of this entry.
53+
*/
54+
public String toString() {
55+
return "(" + name + ", " + score + ")";
56+
}
57+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2014, Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
3+
*
4+
* Developed for use with the book:
5+
*
6+
* Data Structures and Algorithms in Java, Sixth Edition
7+
* Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser
8+
* John Wiley & Sons, 2014
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU General Public License as published by
12+
* the Free Software Foundation, either version 3 of the License, or
13+
* (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*/
23+
package examples.datastructure.arrays;
24+
25+
public class InsertionSort {
26+
27+
/**
28+
* Insertion-sort of an array of characters into nondecreasing order
29+
*/
30+
public static void insertionSort(char[] data) {
31+
int n = data.length;
32+
for (int k = 1; k < n; k++) { // begin with second character
33+
char cur = data[k]; // time to insert cur=data[k]
34+
int j = k; // find correct index j for cur
35+
while (j > 0 && data[j - 1] > cur) { // thus, data[j-1] must go after cur
36+
data[j] = data[j - 1]; // slide data[j-1] rightward
37+
j--; // and consider previous j for cur
38+
}
39+
data[j] = cur; // this is the proper place for cur
40+
}
41+
}
42+
43+
public static void main(String[] args) {
44+
char[] a = {'C', 'E', 'B', 'D', 'A', 'I', 'J', 'L', 'K', 'H', 'G', 'F'};
45+
System.out.println(java.util.Arrays.toString(a));
46+
insertionSort(a);
47+
System.out.println(java.util.Arrays.toString(a));
48+
}
49+
}

0 commit comments

Comments
 (0)