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 {
*/
//TODO write this
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 {
data = new Object[initialCapacity];
}
/**
/**
* 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
* distance from the top of the stack of the occurrence nearest the top
......@@ -39,11 +39,13 @@ public class ArrayStack {
public int search(Object o){
int distance = 1;
//search for the element and increment distance
if(distance <= data.size()){
return distance;
}else{
return -1;
for(Object cmp: this.data){
if(cmp.equals(o)){
return distance;
}
distance ++;
}
return -1;
}
......
......@@ -67,13 +67,17 @@ public class LinkedListStack implements Iterable{
*/
//TODO make sure this works
public int search(Object o){
int distance = 1;
int distance = 0;
//search for the element and increment distance
if(distance <= data.size()){
return distance;
}else{
return -1;
Iterator it = this.iterator();
Object testObject = null;
while(it.hasNext()){
distance ++;
if(it.next().equals(o)){
return distance;
}
}
return -1;
}
public boolean isEmpty() {
......
......@@ -67,11 +67,15 @@ public class Stack {
public int search(Object o){
int distance = 1;
//search for the element and increment distance
if(distance <= data.size()){
return distance;
}else{
return -1;
Node test = this.top;
while(test != null){
if(test.data.equals(o)){
return distance;
}
distance ++;
test = test.getNext();
}
return -1;
}
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