Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Adam Gerber
/
labJava
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
bca93c8c
authored
May 30, 2015
by
Joe Student
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some mods to lab09, mostly notes
parent
270ff0b8
Hide whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
214 additions
and
92 deletions
src/lec01/glab/DigitalToBinary.java
src/lec02/glab/KeyboardInput.java
src/lec03/glab/CalendarTest.java
src/lec03/glab/KeyboardInput_.java
src/lec03/glab/ascii/Asciify.java
src/lec04/glab/employee/EmployeeDriver.java
src/lec04/glab/greg/CalendarTest.java
src/lec04/glab/greg/CalendarTestHaleys.java
src/lec04/glab/realestate/Asciify.java
src/lec05/glab/moreswing/Calc.java
src/lec05/glab/moreswing/LeetTranslator.java
src/lec05/glab/swing/LeetTranslator.java
src/lec06/glab/debugger/IterativeDriver.java
src/lec07/glab/recursion/Fractal.java
src/lec07/glab/recursion/Koch.java
src/lec07/glab/vend/VendMachine.java
src/lec08/FxWizzard.java
src/lec08/glab/blackjack/Hand.java
src/lec08/glab/javafx_group/AdvancedBubbleChartSample.java
src/lec08/glab/javafx_group/App.java
src/lec08/glab/javafx_group/PbarsMain.java
src/lec08/glab/javafx_group/StreamingMediaPlayer.java
src/lec08/glab/javafx_group/TabBrowserMain.java
src/lec08/lunarlander/controller/Game.java
src/lec08/lunarlander/game/model/CommandCenter.java
src/lec08/timpone/finalproject/controller/Game.java
src/lec09/glab/datastructs/MyQueue.java
src/lec09/glab/readme.txt
src/lec09/glab/simpledatastructs/hashmap/SimpleHashMap.java
src/lec09/glab/simpledatastructs/hashmap/SimpleHashMapDriver.java
src/lec09/glab/simpledatastructs/hashtable/SimpleHashTable.java
src/lec09/glab/simpledatastructs/hashtable/SimpleHashTableDriver.java
src/lec09/glab/simpledatastructs/linkedlist/SimpleLinkedList.java
src/lec09/glab/simpledatastructs/tree/SimpleTreeDriver.java
src/lec09/glab/structs/ArrayPriorityQueue.java
src/lec09/glab/structs/ArrayStack.java
src/lec09/glab/structs/BTree.java
src/lec09/glab/structs/HeapPriorityQueue.java
src/lec09/glab/structs/ListQueue.java
src/lec09/glab/structs/Queue.java
src/lec01/glab/DigitalToBinary.java
View file @
bca93c8c
...
...
@@ -40,10 +40,10 @@ public class DigitalToBinary {
//set the strChars[bitLength -1] = "0"
//for some counter init to bitLength - 2 and decremented to zero inclusive
//if the value is greater than= 2^counter
//
add
"1" to the String Array at that location
//
put
"1" to the String Array at that location
//subtract 2^counter from the value
//else
//
add
"0" to the String Array
//
put
"0" to the String Array
//iterate the array while array index < length of array
...
...
@@ -124,21 +124,21 @@ public class DigitalToBinary {
//if the value is greater than= 2^counter
if
(
lValue
>=
(
long
)
Math
.
pow
(
2
,
nCounter
)
){
//
add
"1" to the String Array at that location
//
put
"1" to the String Array at that location
strChars
[
nCounter
]
=
"1"
;
//subtract 2^counter from the value
lValue
-=
(
long
)
Math
.
pow
(
2
,
nCounter
);
}
//else
else
{
//
add
"0" to the String Array
//
put
"0" to the String Array
strChars
[
nCounter
]
=
"0"
;
}
}
//
add
some spaces --for maximum effect
//
put
some spaces --for maximum effect
for
(
int
nC
=
0
;
nC
<
strChars
.
length
;
nC
++
){
//if divisible by 4,
...
...
src/lec02/glab/KeyboardInput.java
View file @
bca93c8c
...
...
@@ -16,7 +16,7 @@ public class KeyboardInput {
//just import from java.util and pass in System.in
Scanner
scnIn
=
new
Scanner
(
System
.
in
);
//let's
add
our sentences to an arraylist
//let's
put
our sentences to an arraylist
ArrayList
<
String
>
strSentences
=
new
ArrayList
<
String
>();
System
.
out
.
println
(
"--------------------------"
);
...
...
src/lec03/glab/CalendarTest.java
View file @
bca93c8c
...
...
@@ -23,12 +23,12 @@ import java.util.GregorianCalendar;
//print out the day of the month e.g. 18
//if startDate == today
//
add
an asterix
//
put
an asterix
//else
//just
add
another space
//just
put
another space
//if the day of week is saturday
//print line break
//
add
one day to the startDate
//
put
one day to the startDate
</pre>
*/
...
...
src/lec03/glab/KeyboardInput_.java
View file @
bca93c8c
...
...
@@ -15,7 +15,7 @@ public class KeyboardInput_ {
//just import from java.util and pass in System.in
Scanner
scnIn
=
new
Scanner
(
System
.
in
);
//let's
add
our sentences to an arraylist
//let's
put
our sentences to an arraylist
ArrayList
<
String
>
strSentences
=
new
ArrayList
<
String
>();
System
.
out
.
println
(
"--------------------------"
);
...
...
src/lec03/glab/ascii/Asciify.java
View file @
bca93c8c
...
...
@@ -30,8 +30,8 @@ public class Asciify {
//get the RGB color of the pixel and store in colPixel
//create a greyscale value from colPixel (values from 0.0 to 255.0) and store in double
//convert greyscale value to an ascii char (@ and # for dark and * and . for light, etc.)
//
add
ascii char to strBuilder
//
add
a line break to strBuilder
//
put
ascii char to strBuilder
//
put
a line break to strBuilder
//copy strBuilder out to clipboard
//give success message for feedback.
...
...
src/lec04/glab/employee/EmployeeDriver.java
View file @
bca93c8c
...
...
@@ -54,12 +54,12 @@ public class EmployeeDriver {
Person
[]
perChicagos
=
new
Person
[
empChicagos
.
length
+
2
];
//
add
all the employees from Chicago
//
put
all the employees from Chicago
for
(
int
nC
=
0
;
nC
<
empChicagos
.
length
;
nC
++)
{
perChicagos
[
nC
]
=
empChicagos
[
nC
];
}
//
add
a new student
//
put
a new student
perChicagos
[
empChicagos
.
length
]
=
new
Student
(
"Adam Gerber"
);
perChicagos
[
empChicagos
.
length
+
1
]
=
new
Student
(
"Joe Student"
,
"CompSci"
);
...
...
src/lec04/glab/greg/CalendarTest.java
View file @
bca93c8c
...
...
@@ -22,12 +22,12 @@ import java.util.GregorianCalendar;
//print out the day of the month e.g. 18
//if startDate == today
//
add
an asterix
//
put
an asterix
//else
//just
add
another space
//just
put
another space
//if the day of week is saturday
//print line break
//
add
one day to the startDate
//
put
one day to the startDate
*/
...
...
@@ -111,7 +111,7 @@ public class CalendarTest {
if
(
greCount
.
get
(
Calendar
.
DAY_OF_WEEK
)
==
SATURDAY
)
System
.
out
.
println
();
//
add
one day
//
put
one day
greCount
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
}
while
(
greCount
.
get
(
Calendar
.
YEAR
)
<
CURRENT_YEAR
+
PROJECT_YEARS
);
...
...
src/lec04/glab/greg/CalendarTestHaleys.java
View file @
bca93c8c
...
...
@@ -23,12 +23,12 @@ import java.util.GregorianCalendar;
//print out the day of the month e.g. 18
//if startDate == today
//
add
an asterix
//
put
an asterix
//else
//just
add
another space
//just
put
another space
//if the day of week is saturday
//print line break
//
add
one day to the startDate
//
put
one day to the startDate
*/
...
...
@@ -51,7 +51,7 @@ public class CalendarTestHaleys {
final
String
[]
SHORT_NAMES
=
new
DateFormatSymbols
().
getShortWeekdays
();
final
String
[]
MONTH_NAMES
=
new
DateFormatSymbols
().
getMonths
();
//create a data structure to hold greg dates and
add
them manually
//create a data structure to hold greg dates and
put
them manually
ArrayList
<
GregorianCalendar
>
greHaleyAppears
=
new
ArrayList
<
GregorianCalendar
>();
greHaleyAppears
.
add
(
new
GregorianCalendar
(
1617
,
5
,
3
));
greHaleyAppears
.
add
(
new
GregorianCalendar
(
1852
,
1
,
2
));
...
...
@@ -114,7 +114,7 @@ public class CalendarTestHaleys {
if
(
greCount
.
get
(
Calendar
.
DAY_OF_WEEK
)
==
SATURDAY
)
System
.
out
.
println
();
//
add
one day
//
put
one day
greCount
.
add
(
Calendar
.
DAY_OF_MONTH
,
1
);
}
while
(
greCount
.
get
(
Calendar
.
YEAR
)
==
greAppear
...
...
src/lec04/glab/realestate/Asciify.java
View file @
bca93c8c
...
...
@@ -24,8 +24,8 @@ public class Asciify {
//get the RGB color of the pixel and store in colPixel
//create a greyscale value from colPixel (values from 0.0 to 255.0) and store in double
//convert greyscale value to an ascii char (@ and # for dark and * and . for light, etc.)
//
add
ascii char to strBuilder
//
add
a line break to strBuilder
//
put
ascii char to strBuilder
//
put
a line break to strBuilder
//copy strBuilder out to clipboard
//give success message for feedback.
...
...
src/lec05/glab/moreswing/Calc.java
View file @
bca93c8c
...
...
@@ -55,7 +55,7 @@ public class Calc {
//create and
add
any listeners
//create and
put
any listeners
mActionListener
=
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
...
...
src/lec05/glab/moreswing/LeetTranslator.java
View file @
bca93c8c
...
...
@@ -39,7 +39,7 @@ public class LeetTranslator {
public
LeetTranslator
()
{
//do any intialization here
populateTable
();
//
add
actionlisteners here
//
put
actionlisteners here
mEditorPane
.
addKeyListener
(
new
KeyAdapter
()
{
@Override
public
void
keyReleased
(
KeyEvent
e
)
{
...
...
@@ -87,7 +87,7 @@ public class LeetTranslator {
Set
<
String
>
setLetters
=
new
HashSet
<
String
>();
//keys from our leet hashtable
//
add
all the chars
//
put
all the chars
for
(
int
nC
=
0
;
nC
<
strSentence
.
length
();
nC
++)
{
setLetters
.
add
(
String
.
valueOf
(
strSentence
.
charAt
(
nC
)));
}
...
...
src/lec05/glab/swing/LeetTranslator.java
View file @
bca93c8c
...
...
@@ -159,7 +159,7 @@ public class LeetTranslator {
Set
<
String
>
setLetters
=
new
HashSet
<
String
>();
//keys from our leet hashtable
//
add
all the chars
//
put
all the chars
for
(
int
nC
=
0
;
nC
<
strSentence
.
length
();
nC
++)
{
setLetters
.
add
(
String
.
valueOf
(
strSentence
.
charAt
(
nC
)));
}
...
...
src/lec06/glab/debugger/IterativeDriver.java
View file @
bca93c8c
...
...
@@ -48,7 +48,7 @@ public class IterativeDriver {
*
* @param nAdd
* @param mdt
* @should
add
days to MyDate
* @should
put
days to MyDate
*/
private
static
void
addDays
(
int
nAdd
,
MyDate
mdt
){
for
(
int
nD
=
0
;
nD
<
nAdd
;
nD
++)
{
...
...
src/lec07/glab/recursion/Fractal.java
View file @
bca93c8c
...
...
@@ -48,7 +48,7 @@ public class Fractal extends JFrame {
}
// end anonymous inner class
);
// end addActionListener
// set up decrease level button to
add
to control panel and
// set up decrease level button to
put
to control panel and
// register listener
decreaseLevelJButton
=
new
JButton
(
"Decrease Level"
);
...
...
@@ -72,7 +72,7 @@ public class Fractal extends JFrame {
}
// end anonymous inner class
);
// end addActionListener
// set up increase level button to
add
to control panel
// set up increase level button to
put
to control panel
// and register listener
increaseLevelJButton
=
new
JButton
(
"Increase Level"
);
controlJPanel
.
add
(
increaseLevelJButton
);
...
...
@@ -96,7 +96,7 @@ public class Fractal extends JFrame {
}
// end anonymous inner class
);
// end addActionListener
// set up levelJLabel to
add
to controlJPanel
// set up levelJLabel to
put
to controlJPanel
levelJLabel
=
new
JLabel
(
"Level: 0"
);
controlJPanel
.
add
(
levelJLabel
);
...
...
@@ -107,7 +107,7 @@ public class Fractal extends JFrame {
mainJPanel
.
add
(
controlJPanel
);
mainJPanel
.
add
(
drawSpace
);
add
(
mainJPanel
);
//
add
JPanel to JFrame
add
(
mainJPanel
);
//
put
JPanel to JFrame
setSize
(
WIDTH
,
HEIGHT
);
// set size of JFrame
setVisible
(
true
);
// display JFrame
...
...
src/lec07/glab/recursion/Koch.java
View file @
bca93c8c
...
...
@@ -83,13 +83,13 @@ public class Koch extends JFrame {
}
// </editor-fold>//GEN-END:initComponents
private
void
resetBtnActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_resetBtnActionPerformed
// TODO
add
your handling code here:
// TODO
put
your handling code here:
draw
.
size
=
600
;
draw
.
repaint
();
}
//GEN-LAST:event_resetBtnActionPerformed
private
void
nextBtnActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_nextBtnActionPerformed
// TODO
add
your handling code here:
// TODO
put
your handling code here:
nxt
++;
draw
.
size
=
s
[
nxt
];
draw
.
repaint
();
...
...
@@ -101,7 +101,7 @@ public class Koch extends JFrame {
}
//GEN-LAST:event_nextBtnActionPerformed
private
void
backBtnActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_backBtnActionPerformed
// TODO
add
your handling code here:
// TODO
put
your handling code here:
nxt
--;
draw
.
size
=
s
[
nxt
];
...
...
src/lec07/glab/vend/VendMachine.java
View file @
bca93c8c
...
...
@@ -17,9 +17,9 @@ ArrayList<Product> prdProducts;
private void initStock() {
prdProducts = new ArrayList<Product>();
prdProducts.
add
(new Product("Heath", 1.25));
prdProducts.
add
(new Product("PayDay", 1.25));
prdProducts.
add
(new Product("Pop Tart", 1.75));
prdProducts.
put
(new Product("Heath", 1.25));
prdProducts.
put
(new Product("PayDay", 1.25));
prdProducts.
put
(new Product("Pop Tart", 1.75));
...
...
...
src/lec08/FxWizzard.java
View file @
bca93c8c
...
...
@@ -41,7 +41,7 @@ public class FxWizzard extends javax.swing.JFrame {
+
" Parent root = FXMLLoader.load(getClass().getResource(\"/%s.fxml\"));\n"
+
"\n"
+
" Scene scene = new Scene(root);\n"
+
" scene.getStylesheets().
add
(\"/%s.css\");\n"
+
" scene.getStylesheets().
put
(\"/%s.css\");\n"
+
"\n"
+
" stage.setTitle(\"%s\");\n"
+
" stage.setScene(scene);\n"
...
...
@@ -316,15 +316,15 @@ public class FxWizzard extends javax.swing.JFrame {
}
// </editor-fold>
private
void
txtNameActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
// TODO
add
your handling code here:
// TODO
put
your handling code here:
}
private
void
chkControllerActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
// TODO
add
your handling code here:
// TODO
put
your handling code here:
}
private
void
btnGenerateActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
// TODO
add
your handling code here:
// TODO
put
your handling code here:
//mvn exec:java -Dexec.mainClass="edu.uchicago.gerber.PdfMain"
if
(
txtName
.
getText
().
equals
(
""
))
{
javax
.
swing
.
JOptionPane
.
showMessageDialog
(
this
,
"The 'Base Name' field must not be empty"
);
...
...
@@ -365,21 +365,21 @@ public class FxWizzard extends javax.swing.JFrame {
}
private
void
chkGitignoreActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
// TODO
add
your handling code here:
// TODO
put
your handling code here:
}
private
void
txtMainActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
// TODO
add
your handling code here:
// TODO
put
your handling code here:
}
private
void
btnGitActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
// TODO
add
your handling code here:
// TODO
put
your handling code here:
writeGit
(
strGIT
);
}
private
void
btnArchActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
// TODO
add
your handling code here:
// TODO
put
your handling code here:
String
strLocal
=
"mvn archetype:generate -DarchetypeGroupId=com.zenjava -DarchetypeArtifactId=javafx-basic-archetype -DarchetypeVersion=1.1"
;
Clipboard
clpbrd
=
Toolkit
.
getDefaultToolkit
().
getSystemClipboard
();
StringSelection
stringSelection
=
new
StringSelection
(
strLocal
);
...
...
src/lec08/glab/blackjack/Hand.java
View file @
bca93c8c
...
...
@@ -25,7 +25,7 @@ public class Hand {
}
public
int
getHardValue
()
{
//
add
up the values of hte cards on face value; aces are 11
//
put
up the values of hte cards on face value; aces are 11
int
nRet
=
0
;
for
(
Card
car
:
carHandCards
)
{
...
...
@@ -37,7 +37,7 @@ public class Hand {
public
int
getSoftValue
()
{
//
add
up ; count aces as one
//
put
up ; count aces as one
int
nRet
=
0
;
for
(
Card
car
:
carHandCards
)
{
if
(
car
.
getValue
()
==
11
)
{
...
...
src/lec08/glab/javafx_group/AdvancedBubbleChartSample.java
View file @
bca93c8c
...
...
@@ -45,7 +45,7 @@ public class AdvancedBubbleChartSample extends Application {
bc
.
setTitle
(
"Advanced BubbleChart"
);
xAxis
.
setLabel
(
"X Axis"
);
yAxis
.
setLabel
(
"Y Axis"
);
//
add
starting data
//
put
starting data
XYChart
.
Series
<
Number
,
Number
>
series1
=
new
XYChart
.
Series
<
Number
,
Number
>();
series1
.
setName
(
"Data Series 1"
);
for
(
int
i
=
0
;
i
<
20
;
i
++)
series1
.
getData
().
add
(
...
...
src/lec08/glab/javafx_group/App.java
View file @
bca93c8c
...
...
@@ -97,7 +97,7 @@ public class App extends Application {
Scene
scene
=
new
Scene
(
root
,
800
,
800
);
//
add
some dims
Scene
scene
=
new
Scene
(
root
,
800
,
800
);
//
put
some dims
primaryStage
.
setScene
(
scene
);
primaryStage
.
setTitle
(
"Hello World"
);
primaryStage
.
show
();
...
...
src/lec08/glab/javafx_group/PbarsMain.java
View file @
bca93c8c
...
...
@@ -37,7 +37,7 @@ public class PbarsMain extends Application {
Group
root
=
new
Group
();
Scene
scene
=
new
Scene
(
root
,
300
,
150
);
// scene.getStylesheets().
add
("progresssample/Style.css");
// scene.getStylesheets().
put
("progresssample/Style.css");
stage
.
setScene
(
scene
);
stage
.
setTitle
(
"Progress Controls"
);
...
...
src/lec08/glab/javafx_group/StreamingMediaPlayer.java
View file @
bca93c8c
...
...
@@ -53,7 +53,7 @@ public class StreamingMediaPlayer extends Application {
playerPane
.
setMinSize
(
480
,
360
);
playerPane
.
setPrefSize
(
480
,
360
);
playerPane
.
setMaxSize
(
480
,
360
);
// getStylesheets().
add
("ensemble/samples/media/OverlayMediaPlayer.css");
// getStylesheets().
put
("ensemble/samples/media/OverlayMediaPlayer.css");
root
.
getChildren
().
add
(
playerPane
);
}
...
...
src/lec08/glab/javafx_group/TabBrowserMain.java
View file @
bca93c8c
...
...
@@ -55,7 +55,7 @@ public class TabBrowserMain extends Application {
final
Button
btn
=
new
Button
();
//btn.setPrefSize(500, 30);
btn
.
setPrefHeight
(
30
);
btn
.
setText
(
"Click to
add
tab"
);
btn
.
setText
(
"Click to
put
tab"
);
// tabPane.setPrefSize(500, 600);
tabPane
.
setSide
(
Side
.
TOP
);
...
...
src/lec08/lunarlander/controller/Game.java
View file @
bca93c8c
...
...
@@ -153,8 +153,8 @@ public class Game implements Runnable, KeyListener {
//for each mark-for-removal
//remove it
//for each mark-for-
add
//
add
it
//for each mark-for-
put
//
put
it
//@formatter:on
//we use this ArrayList to keep pairs of movMovables/movTarget for either
...
...
@@ -226,7 +226,7 @@ public class Game implements Runnable, KeyListener {
for
(
Tuple
tup
:
tupMarkForRemovals
)
tup
.
removeMovable
();
//
add
these objects to their appropriate ArrayLists
//
put
these objects to their appropriate ArrayLists
//this happens after the above iterations are done
for
(
Tuple
tup
:
tupMarkForAdds
)
tup
.
addMovable
();
...
...
@@ -421,7 +421,7 @@ public class Game implements Runnable, KeyListener {
}
if
(
nTick
%
(
NEW_LEVEL
-
nLevel
*
7
)
==
0
)
{
//CommandCenter.movFloaters.
add
(new NewShipFloater());
//CommandCenter.movFloaters.
put
(new NewShipFloater());
CommandCenter
.
spawnTerrain
(
CommandCenter
.
getLevel
());
CommandCenter
.
setLevel
(
CommandCenter
.
getLevel
()
+
1
);
}
...
...
@@ -557,7 +557,7 @@ public class Game implements Runnable, KeyListener {
// ===============================================
// ==A tuple takes a reference to an ArrayList and a reference to a Movable
//This class is used in the collision detection method, to avoid mutating the array list while we are iterating
// it has two public methods that either remove or
add the movable from the appropriate ArrayList
// it has two public methods that either remove or
put the movable from the appropriate ArrayList
// ===============================================
class
Tuple
{
...
...
src/lec08/lunarlander/game/model/CommandCenter.java
View file @
bca93c8c
...
...
@@ -61,7 +61,7 @@ public class CommandCenter {
nCounter
++;
}
//CommandCenter.movFoes.
add
(terrainBlock);
//CommandCenter.movFoes.
put
(terrainBlock);
}
...
...
@@ -76,7 +76,7 @@ public class CommandCenter {
// bLanding = (nC % 150 == 0);
// nHeight = Game.R.nextInt(90) + 10;
//
// movFoes.
add
(new TerrainBlock(new Point(nC, nGameHeight -nHeight), bLanding));
// movFoes.
put
(new TerrainBlock(new Point(nC, nGameHeight -nHeight), bLanding));
// }
// }
...
...
src/lec08/timpone/finalproject/controller/Game.java
View file @
bca93c8c
...
...
@@ -308,7 +308,7 @@ public class Game implements Runnable, KeyListener, MouseListener, MouseMotionLi
tup
.
removeMovable
();
}
//
add
these objects to their appropriate ArrayLists; this happens after the above iterations are done
//
put
these objects to their appropriate ArrayLists; this happens after the above iterations are done
for
(
Tuple
tup
:
tupMarkForAdds
)
tup
.
addMovable
();
...
...
@@ -698,7 +698,7 @@ public class Game implements Runnable, KeyListener, MouseListener, MouseMotionLi
* This inner class remains unchanged from the original game base
*
* A tuple takes a reference to an ArrayList and a reference to a Movable. This class is used in the collision detection
* method, to avoid mutating the array list while we are iterating. It has two public methods that either remove or
add the
* method, to avoid mutating the array list while we are iterating. It has two public methods that either remove or
put the
* movable from the appropriate ArrayList
*/
...
...
src/lec09/glab/datastructs/MyQueue.java
View file @
bca93c8c
...
...
@@ -173,7 +173,7 @@ public class MyQueue<T> extends AbstractQueue<T> {
}
}
//this is like
add but safer.
//this is like
put but safer.
@Override
public
boolean
offer
(
Object
obj
)
{
// TODO Auto-generated method stub
...
...
src/lec09/glab/readme.txt
View file @
bca93c8c
recreate the datastructs from scratch using a singly-linked-list or a binary tree or hash table.
\ No newline at end of file
structs - from A/P computer science
searchsort - demos of searc and sort algorithms created by yours truly
simpledatastrcuts - implementation of most basic data structs - hand-rolled - using list-nodes and tree-nodes that we created.
recreate the datastructs from scratch using the listNode and treeNode.
start with Queue:
What is a Node<T>
//inner class
class Node<T> {
private T typValue;
private Node<T> nodNext;
Node(T typInit, Node<T> nodInit) {
typValue = typInit;
nodNext = nodInit;
}
T getValue() {
return typValue;
}
Node<T> getNext() {
return nodNext;
}
void setValue(T typValue) {
this.typValue = typValue;
}
void setNext(Node<T> nodNext) {
this.nodNext = nodNext;
}
}
What is an Iterator
//inner class
class LinkedListIterator implements Iterator<T> {
private Node<T> nodCurr; // Current position
LinkedListIterator() {
nodCurr = nodHead;
}
@Override
public boolean hasNext() {
return (nodCurr != null);
}
@Override
public T next() {
T typ = nodCurr.getValue();
nodCurr = nodCurr.getNext();
return typ;
}
@Override
public void remove() {
//we already have remove methods. not implemented.
}
}//end iterator
\ No newline at end of file
src/lec09/glab/simpledatastructs/hashmap/SimpleHashMap.java
View file @
bca93c8c
package
lec09
.
glab
.
simpledatastructs
.
hashmap
;
import
java.util.Map
;
// this class is generic
public
class
SimpleHashMap
<
K
,
V
>
{
public
class
SimpleHashMap
<
K
,
V
>
{
private
MapNode
<
K
,
V
>[]
nodHashes
;
...
...
@@ -38,7 +39,7 @@ public class SimpleHashMap<K,V> {
// ==ADD
// ===============================================
//O(1) very fast
public
void
add
(
K
typKey
,
V
typValue
)
{
public
void
put
(
K
typKey
,
V
typValue
)
{
int
nHash
=
typKey
.
hashCode
();
nHash
=
Math
.
abs
(
nHash
);
...
...
@@ -78,7 +79,7 @@ public class SimpleHashMap<K,V> {
public
String
contains
(
K
typKey
)
{
String
strR
=
""
;
int
nCount
=
0
;
int
nCount
=
0
;
//just used to show how many times we had to iterate in the event of collission
int
nHash
=
typKey
.
hashCode
();
nHash
=
Math
.
abs
(
nHash
);
...
...
@@ -86,7 +87,7 @@ public class SimpleHashMap<K,V> {
MapNode
<
K
,
V
>
nodCurrent
=
nodHashes
[
nHash
];
while
(
nodCurrent
!=
null
)
{
nCount
++;
nCount
++;
//collission counter only
if
(
nodCurrent
.
getKey
().
equals
(
typKey
))
{
strR
+=
nodCurrent
.
getValue
()
+
" found at index "
+
nHash
+
" : "
;
break
;
...
...
src/lec09/glab/simpledatastructs/hashmap/SimpleHashMapDriver.java
View file @
bca93c8c
package
lec09
.
glab
.
simpledatastructs
.
hashmap
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
SimpleHashMapDriver
{
/**
...
...
@@ -9,22 +12,45 @@ public class SimpleHashMapDriver {
//try small numbers like 2, or 11
SimpleHashMap
<
Integer
,
String
>
strCities
=
new
SimpleHashMap
<
Integer
,
String
>(
15
);
Map
<
Integer
,
String
>
map
=
new
HashMap
<>();
System
.
out
.
println
(
"hashcode() for 60001: "
+
new
Integer
(
60001
).
hashCode
());
System
.
out
.
println
(
"hashcode() for 60001: "
+
new
Integer
(
60001
).
hashCode
());
//will not allow dups
strCities
.
add
(
60001
,
"Chicago"
);
strCities
.
add
(
60001
,
"Evanston"
);
strCities
.
add
(
20001
,
"New York"
);
strCities
.
add
(
90001
,
"Los Angeles"
);
strCities
.
add
(
99998
,
"Shanghai"
);
strCities
.
add
(
99999
,
"Moscow"
);
strCities
.
add
(
99999
,
"Moscow"
);
strCities
.
put
(
60001
,
"Chicago"
);
strCities
.
put
(
60001
,
"Evanston"
);
strCities
.
put
(
20001
,
"New York"
);
strCities
.
put
(
90001
,
"Los Angeles"
);
strCities
.
put
(
99998
,
"Shanghai"
);
strCities
.
put
(
99999
,
"Moscow"
);
strCities
.
put
(
99999
,
"Moscow"
);
//will not allow dups
map
.
put
(
60001
,
"Chicago"
);
map
.
put
(
60001
,
"Evanston"
);
map
.
put
(
20001
,
"New York"
);
map
.
put
(
90001
,
"Los Angeles"
);
map
.
put
(
99998
,
"Shanghai"
);
map
.
put
(
99999
,
"Moscow"
);
map
.
put
(
99999
,
"Moscow"
);
strCities
.
printIterate
();
System
.
out
.
println
();
System
.
out
.
println
(
strCities
.
contains
(
99998
));
System
.
out
.
println
(
"#####################################"
);
//iter (using templates)
for
(
Integer
integer
:
map
.
keySet
())
{
System
.
out
.
println
(
"Key: "
+
integer
+
" : Value: "
+
map
.
get
(
integer
));
}
System
.
out
.
println
(
map
.
containsKey
(
99998
));
...
...
src/lec09/glab/simpledatastructs/hashtable/SimpleHashTable.java
View file @
bca93c8c
...
...
@@ -51,7 +51,7 @@ public class SimpleHashTable<T> {
nodHashes
[
nHash
]
=
new
Node
<
T
>(
typ
,
null
);
}
else
{
//
add
it to the beginning
//
put
it to the beginning
nodHashes
[
nHash
]
=
new
Node
<
T
>(
typ
,
nodHashes
[
nHash
]);
...
...
src/lec09/glab/simpledatastructs/hashtable/SimpleHashTableDriver.java
View file @
bca93c8c
package
lec09
.
glab
.
simpledatastructs
.
hashtable
;
import
java.util.Date
;
public
class
SimpleHashTableDriver
{
/**
...
...
@@ -9,7 +11,23 @@ public class SimpleHashTableDriver {
//try small numbers like 2, or 11
SimpleHashTable
<
String
>
strCities
=
new
SimpleHashTable
<
String
>(
11
);
System
.
out
.
println
(
"hashcode() for Chicago: "
+
"Chicago"
.
hashCode
());
System
.
out
.
println
(
"hashcode() for Chicago: "
+
"Chicago"
.
hashCode
());
System
.
out
.
println
(
"hashcode() for Date(12,15,2010): "
+
new
Date
(
12
,
15
,
2010
).
hashCode
());
System
.
out
.
println
(
"hashcode() for Date(12,15,2010): "
+
new
Date
(
12
,
15
,
2010
).
hashCode
());
//hashcode() method of Date
// public int hashCode() {
// long ht = this.getTime();
// return (int) ht ^ (int) (ht >> 32);
// }
//will allow duplicates -- watch-out
strCities
.
add
(
"Chicago"
);
strCities
.
add
(
"New York"
);
...
...
src/lec09/glab/simpledatastructs/linkedlist/SimpleLinkedList.java
View file @
bca93c8c
package
lec09
.
glab
.
simpledatastructs
.
linkedlist
;
import
java.util.Iterator
;
import
java.util.List
;
//this class is generic
public
class
SimpleLinkedList
<
T
>
{
public
class
SimpleLinkedList
<
T
>
{
private
Node
<
T
>
nodFirst
;
private
Node
<
T
>
nodLast
;
...
...
@@ -327,6 +328,7 @@ public class SimpleLinkedList<T> {
}
//no setters, just getters
public
int
size
()
{
return
nSize
;
...
...
src/lec09/glab/simpledatastructs/tree/SimpleTreeDriver.java
View file @
bca93c8c
...
...
@@ -9,6 +9,8 @@ public class SimpleTreeDriver {
public
static
void
main
(
String
[]
args
)
{
SimpleTree
comTeams
=
new
SimpleTree
();
comTeams
.
insert
(
"Bears"
);
comTeams
.
insert
(
"Vikings"
);
...
...
src/lec09/glab/structs/ArrayPriorityQueue.java
View file @
bca93c8c
...
...
@@ -16,13 +16,13 @@ import java.util.List;
* <P>
* <TABLE>
* <th> operation <th> worst case <th> average case <tr>
* <td>
add
<td> O(1) <td> O(1) <tr>
* <td>
put
<td> O(1) <td> O(1) <tr>
* <td> peekMin <td> O(n) <td> O(n) <tr>
* <td> removeMin <td> O(n) <td> O(n) <tr>
* </TABLE>
* <P>
* The underlying storage is <code>java.util.ArrayList</code> which
* supports constant time
add
(to end), but which requires linear
* supports constant time
put
(to end), but which requires linear
* search to find the smallest element.
* <P>
* This implementation is provided
...
...
src/lec09/glab/structs/ArrayStack.java
View file @
bca93c8c
...
...
@@ -12,7 +12,7 @@ import java.util.ArrayList;
* All stack functions execute in <em>O(1)</em> or constant time
* amortized over several stack operations. This is because the
* underlying storage is <code>java.util.ArrayList</code> which
* supports constant time access,
add
(to end), and remove
* supports constant time access,
put
(to end), and remove
* (from end).
* <P>
* This implementation is provided
...
...
src/lec09/glab/structs/BTree.java
View file @
bca93c8c
...
...
@@ -27,7 +27,7 @@ public class BTree
{
addNode
(
nodRoot
,
nodNew
);
}
}
//end
add
}
//end
put
private
void
addNode
(
BNode
nodCur
,
BNode
nodNew
)
{
...
...
src/lec09/glab/structs/HeapPriorityQueue.java
View file @
bca93c8c
...
...
@@ -17,7 +17,7 @@ import java.util.List;
* <th align="center" width=40%> operation
* <th align="center" width=40%> worst case
* <th align="center"> average case <tr>
* <td>
add
<td> O(log n) <td> O(1) <tr>
* <td>
put
<td> O(log n) <td> O(1) <tr>
* <td> peekMin <td> O(1) <td> O(1) <tr>
* <td> removeMin <td> O(log n) <td> O(log n) <tr>
* </TABLE>
...
...
@@ -39,7 +39,7 @@ public class HeapPriorityQueue implements PriorityQueue
public
HeapPriorityQueue
()
{
items
=
new
ArrayList
();
items
.
add
(
null
);
// first
add
should go at index 1
items
.
add
(
null
);
// first
put
should go at index 1
mySize
=
0
;
}
...
...
@@ -100,7 +100,7 @@ public class HeapPriorityQueue implements PriorityQueue
child
++;
}
// if item to be added <= child, stop and
add
the item
// if item to be added <= child, stop and
put
the item
if
(
last
.
compareTo
(
items
.
get
(
child
))
<=
0
)
{
break
;
...
...
src/lec09/glab/structs/ListQueue.java
View file @
bca93c8c
...
...
@@ -12,7 +12,7 @@ import java.util.LinkedList;
* All queue functions execute in <em>O(1)</em> or constant time
* amortized over several queue operations. This is because the
* underlying storage is <code>java.util.LinkedList</code> which
* supports constant time access,
add
(to end and front), and remove
* supports constant time access,
put
(to end and front), and remove
* (from end and front).
* <P>
* This implementation is provided
...
...
src/lec09/glab/structs/Queue.java
View file @
bca93c8c
...
...
@@ -27,7 +27,7 @@ package lec09.glab.structs;
* {
* ArrayList list = new ArrayList();
* while (! q.isEmpty()) {
* list.
add
(q.dequeue());
* list.
put
(q.dequeue());
* }
* for(int k=list.size()-1; k >= 0; k--) {
* q.enqueue(list.get(k));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment