Skip to content

Commit

Permalink
Merge pull request #14 from CottonChou/master
Browse files Browse the repository at this point in the history
Queue&Stack
  • Loading branch information
zeyuanpinghe authored Feb 27, 2017
2 parents c33af41 + 82abdbd commit e495117
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
38 changes: 38 additions & 0 deletions group19/398129523/Queue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.coding.work;

import java.util.NoSuchElementException;



public class Queue {
private Object[] elementdate;
private int size;
private int index;

public void enQueue(Object o) {
if(o == null){
throw new IllegalArgumentException();
}
elementdate[index++] = o;
size = index + 1;
}

public Object deQueue(){
if (size == 0) {
throw new NoSuchElementException();
}else{
Object out = elementdate[0];
System.arraycopy(elementdate, 1, elementdate, 0, size - 1);
return out;
}
}

public boolean isEmpty(){

return size == 0;
}

public int size() {
return size;
}
}
36 changes: 36 additions & 0 deletions group19/398129523/Stack
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.coding.work;

import java.util.NoSuchElementException;

public class Stack {
private Object[] elementdata;
private int size;
private int index;

public void push(Object o) {
if (o == null) {
throw new IllegalArgumentException();

}
size = index + 1;
elementdata[index++] = o;
}

public Object pop() {
if (size == 0) {
throw new NoSuchElementException();
}
size --;
return elementdata[index--];
}

@SuppressWarnings("unused")
private boolean isEmpty() {
return size == 0;
}

private int size() {
return size;
}

}

0 comments on commit e495117

Please sign in to comment.