-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
586c0c1
commit ece0ed7
Showing
17 changed files
with
679 additions
and
29 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
example/MojiEclipseQuickStart/.settings/org.jboss.ide.eclipse.as.core.prefs
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//----------------------------------------------------------------------------- | ||
// FileIO.java | ||
// Illustrates file IO and tokenization using String.split() | ||
//----------------------------------------------------------------------------- | ||
|
||
import java.io.*; | ||
import java.util.Scanner; | ||
|
||
class FileIO{ | ||
public static void main(String[] args) throws IOException{ | ||
Scanner in = null; | ||
PrintWriter out = null; | ||
String line = null; | ||
String[] token = null; | ||
int i, n, lineNumber = 0; | ||
|
||
if(args.length < 2){ | ||
System.err.println("Usage: FileIO infile outfile"); | ||
System.exit(1); | ||
} | ||
|
||
in = new Scanner(new File(args[0])); | ||
out = new PrintWriter(new FileWriter(args[1])); | ||
|
||
while( in.hasNextLine() ){ | ||
lineNumber++; | ||
line = in.nextLine()+" "; // add extra space so split works right | ||
token = line.split("\\s+"); // split line around white space | ||
n = token.length; | ||
out.println("Line "+lineNumber+" contains "+n+" token"+(n==1?"":"s")+":"); | ||
for(i=0; i<n; i++){ | ||
out.println(token[i]); | ||
} | ||
out.println(); | ||
} | ||
|
||
in.close(); | ||
out.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#------------------------------------------------------------------------------ | ||
# Makefile for FileIO | ||
#------------------------------------------------------------------------------ | ||
|
||
MAINCLASS = FileIO | ||
JAVAC = javac -Xlint | ||
JAVASRC = $(wildcard *.java) | ||
SOURCES = $(JAVASRC) Makefile README | ||
CLASSES = $(patsubst %.java, %.class, $(JAVASRC)) | ||
JARCLASSES = $(patsubst %.class, %*.class, $(CLASSES)) | ||
JARFILE = $(MAINCLASS) | ||
|
||
all: $(JARFILE) | ||
|
||
$(JARFILE): $(CLASSES) | ||
echo Main-class: $(MAINCLASS) > Manifest | ||
jar cvfm $(JARFILE) Manifest $(JARCLASSES) | ||
chmod +x $(JARFILE) | ||
rm Manifest | ||
|
||
%.class: %.java | ||
$(JAVAC) $< | ||
|
||
clean: | ||
rm -f *.class $(JARFILE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//----------------------------------------------------------------------------- | ||
// ListClient.java | ||
// A test client for the List ADT. Use this to test your list module. The | ||
// correct output is given below. | ||
//----------------------------------------------------------------------------- | ||
|
||
public class ListClient{ | ||
public static void main(String[] args){ | ||
List A = new List(); | ||
List B = new List(); | ||
|
||
for(int i=1; i<=20; i++){ | ||
A.append(i); | ||
B.prepend(i); | ||
} | ||
System.out.println(A); | ||
System.out.println(B); | ||
|
||
for(A.moveFront(); A.index()>=0; A.moveNext()){ | ||
System.out.print(A.get()+" "); | ||
} | ||
System.out.println(); | ||
for(B.moveBack(); B.index()>=0; B.movePrev()){ | ||
System.out.print(B.get()+" "); | ||
} | ||
System.out.println(); | ||
|
||
List C = A.copy(); | ||
System.out.println(A.equals(B)); | ||
System.out.println(B.equals(C)); | ||
System.out.println(C.equals(A)); | ||
|
||
A.moveFront(); | ||
for(int i=0; i<5; i++) A.moveNext(); // at index 5 | ||
A.insertBefore(-1); // at index 6 | ||
for(int i=0; i<9; i++) A.moveNext(); // at index 15 | ||
A.insertAfter(-2); | ||
for(int i=0; i<5; i++) A.movePrev(); // at index 10 | ||
A.delete(); | ||
System.out.println(A); | ||
System.out.println(A.length()); | ||
A.clear(); | ||
System.out.println(A.length()); | ||
} | ||
} | ||
|
||
// Output of this program: | ||
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ||
// 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 | ||
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ||
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ||
// false | ||
// false | ||
// true | ||
// 1 2 3 4 5 -1 6 7 8 9 11 12 13 14 15 -2 16 17 18 19 20 | ||
// 21 | ||
// 0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#------------------------------------------------------------------------------ | ||
# Makefile for Queue | ||
#------------------------------------------------------------------------------ | ||
|
||
MAINCLASS = QueueTest | ||
JAVAC = javac -Xlint | ||
JAVASRC = $(wildcard *.java) | ||
SOURCES = $(JAVASRC) Makefile README | ||
CLASSES = $(patsubst %.java, %.class, $(JAVASRC)) | ||
JARCLASSES = $(patsubst %.class, %*.class, $(CLASSES)) | ||
JARFILE = $(MAINCLASS) | ||
|
||
all: $(JARFILE) | ||
|
||
$(JARFILE): $(CLASSES) | ||
echo Main-class: $(MAINCLASS) > Manifest | ||
jar cvfm $(JARFILE) Manifest $(JARCLASSES) | ||
chmod +x $(JARFILE) | ||
rm Manifest | ||
|
||
%.class: %.java | ||
$(JAVAC) $< | ||
|
||
clean: | ||
rm -f *.class $(JARFILE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
//----------------------------------------------------------------------------- | ||
// Queue.java | ||
// An integer queue ADT | ||
// | ||
// This file constitutes the solution to the first excercise in the ADT handout. | ||
// Recall that all ADT operations must state their own preconditions in a comment | ||
// block, then check that those conditions are satisfied. If a precondition is | ||
// violated, the ADT operation should cause the program to quit with a useful error | ||
// message. See functions getFront() and Dequeue() below for examples on how to do | ||
// this. Observe that we've added two other operations called equals() and copy(). | ||
// | ||
//----------------------------------------------------------------------------- | ||
|
||
class Queue{ | ||
|
||
private class Node{ | ||
// Fields | ||
int data; | ||
Node next; | ||
|
||
// Constructor | ||
Node(int data) { this.data = data; next = null; } | ||
|
||
// toString(): overrides Object's toString() method | ||
public String toString() { | ||
return String.valueOf(data); | ||
} | ||
|
||
// equals(): overrides Object's equals() method | ||
public boolean equals(Object x){ | ||
boolean eq = false; | ||
Node that; | ||
if(x instanceof Node){ | ||
that = (Node) x; | ||
eq = (this.data==that.data); | ||
} | ||
return eq; | ||
} | ||
} | ||
|
||
// Fields | ||
private Node front; | ||
private Node back; | ||
private int length; | ||
|
||
// Constructor | ||
Queue() { | ||
front = back = null; | ||
length = 0; | ||
} | ||
|
||
|
||
// Access Functions -------------------------------------------------------- | ||
|
||
// isEmpty() | ||
// Returns true if this Queue is empty, false otherwise. | ||
boolean isEmpty() { | ||
return length==0; | ||
} | ||
|
||
// getLength() | ||
// Returns length of this Queue. | ||
int getLength() { | ||
return length; | ||
} | ||
|
||
// getFront() | ||
// Returns front element. | ||
// Pre: !this.isEmpty() | ||
int getFront(){ | ||
if( this.isEmpty() ){ | ||
throw new RuntimeException( | ||
"Queue Error: getFront() called on empty Queue"); | ||
} | ||
return front.data; | ||
} | ||
|
||
// Manipulation Procedures ------------------------------------------------- | ||
|
||
// Enqueue() | ||
// Appends data to back of this Queue. | ||
void Enqueue(int data){ | ||
Node N = new Node(data); | ||
if( this.isEmpty() ) { | ||
front = back = N; | ||
}else{ | ||
back.next = N; | ||
back = N; | ||
} | ||
length++; | ||
} | ||
|
||
// Dequeue() | ||
// Deletes front element from this Queue. | ||
// Pre: !this.isEmpty() | ||
void Dequeue(){ | ||
if(this.isEmpty()){ | ||
throw new RuntimeException( | ||
"Queue Error: Dequeue() called on empty Queue"); | ||
} | ||
if(this.length>1){ | ||
front = front.next; | ||
}else{ | ||
front = back = null; | ||
} | ||
length--; | ||
} | ||
|
||
|
||
// Other Functions --------------------------------------------------------- | ||
|
||
// toString() | ||
// Overides Object's toString() method. | ||
public String toString(){ | ||
StringBuffer sb = new StringBuffer(); | ||
Node N = front; | ||
while(N!=null){ | ||
sb.append(" "); | ||
sb.append(N.toString()); | ||
N = N.next; | ||
} | ||
return new String(sb); | ||
} | ||
|
||
// equals() | ||
// Overrides Object's equals() method. Returns true if x is a Queue storing | ||
// the same integer sequence as this Queue, false otherwise. | ||
public boolean equals(Object x){ | ||
boolean eq = false; | ||
Queue Q; | ||
Node N, M; | ||
|
||
if(x instanceof Queue){ | ||
Q = (Queue)x; | ||
N = this.front; | ||
M = Q.front; | ||
eq = (this.length==Q.length); | ||
while( eq && N!=null ){ | ||
eq = N.equals(M); | ||
N = N.next; | ||
M = M.next; | ||
} | ||
} | ||
return eq; | ||
} | ||
|
||
// copy() | ||
// Returns a new Queue identical to this Queue. | ||
Queue copy(){ | ||
Queue Q = new Queue(); | ||
Node N = this.front; | ||
|
||
while( N!=null ){ | ||
Q.Enqueue(N.data); | ||
N = N.next; | ||
} | ||
return Q; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//----------------------------------------------------------------------------- | ||
// QueueTest.java | ||
// A test client for the Queue ADT | ||
//----------------------------------------------------------------------------- | ||
|
||
class QueueTest{ | ||
public static void main(String[] args){ | ||
Queue A = new Queue(); | ||
Queue B = new Queue(); | ||
Queue C; | ||
|
||
for(int i=1; i<=10; i++){ | ||
A.Enqueue(i); | ||
B.Enqueue(11-i); | ||
} | ||
System.out.println("A = " + A); | ||
System.out.println("B = " + B); | ||
|
||
for(int i=1; i<=6; i++){ | ||
A.Enqueue(B.getFront()); | ||
B.Dequeue(); | ||
} | ||
System.out.println("A = " + A); | ||
System.out.println("B = " + B); | ||
C = A.copy(); | ||
System.out.println("C = " + C); | ||
System.out.println("A " + (A.equals(B)?"equals":"does not equal") + " B"); | ||
System.out.println("A " + (A.equals(C)?"equals":"does not equal") + " C"); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.