Commit e0b21e2c authored by michael lundquist's avatar michael lundquist
Browse files

Adding untested code for the required methods. Now I need to test these methods.

parent 178073fd
...@@ -100,7 +100,11 @@ public class ArrayQueue { ...@@ -100,7 +100,11 @@ public class ArrayQueue {
*/ */
//TODO write this //TODO write this
public boolean offer(Object e){ public boolean offer(Object e){
return false; if(manyItems >= data.length){
return false;
}
this.add(e);
return true;
} }
} }
\ No newline at end of file
...@@ -21,7 +21,7 @@ public class ArrayStack { ...@@ -21,7 +21,7 @@ public class ArrayStack {
data = new Object[initialCapacity]; data = new Object[initialCapacity];
} }
/** /**
* Returns the 1-based position where an object is on this stack. If the * Returns the 1-based position where an object is on this stack. If the
* object o occurs as an item in this stack, this method returns the * object o occurs as an item in this stack, this method returns the
* distance from the top of the stack of the occurrence nearest the top * distance from the top of the stack of the occurrence nearest the top
...@@ -39,11 +39,13 @@ public class ArrayStack { ...@@ -39,11 +39,13 @@ public class ArrayStack {
public int search(Object o){ public int search(Object o){
int distance = 1; int distance = 1;
//search for the element and increment distance //search for the element and increment distance
if(distance <= data.size()){ for(Object cmp: this.data){
return distance; if(cmp.equals(o)){
}else{ return distance;
return -1; }
distance ++;
} }
return -1;
} }
......
...@@ -67,13 +67,17 @@ public class LinkedListStack implements Iterable{ ...@@ -67,13 +67,17 @@ public class LinkedListStack implements Iterable{
*/ */
//TODO make sure this works //TODO make sure this works
public int search(Object o){ public int search(Object o){
int distance = 1; int distance = 0;
//search for the element and increment distance //search for the element and increment distance
if(distance <= data.size()){ Iterator it = this.iterator();
return distance; Object testObject = null;
}else{ while(it.hasNext()){
return -1; distance ++;
if(it.next().equals(o)){
return distance;
}
} }
return -1;
} }
public boolean isEmpty() { public boolean isEmpty() {
......
...@@ -67,11 +67,15 @@ public class Stack { ...@@ -67,11 +67,15 @@ public class Stack {
public int search(Object o){ public int search(Object o){
int distance = 1; int distance = 1;
//search for the element and increment distance //search for the element and increment distance
if(distance <= data.size()){ Node test = this.top;
return distance; while(test != null){
}else{ if(test.data.equals(o)){
return -1; return distance;
}
distance ++;
test = test.getNext();
} }
return -1;
} }
public Object pop(){ public Object pop(){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment