Commit 86c664a5 authored by michael lundquist's avatar michael lundquist
Browse files

Fixing a path in the docker-compose script and adding more files for the assignment.

parent 2fde9c32
Pipeline #4087 failed with stage
in 1 minute and 18 seconds
......@@ -13,7 +13,7 @@ before_script:
- export M2_HOME=/opt/apache-maven-3.6.0
- export M2=$M2_HOME/bin
- export PATH=$M2:$PATH
- cd $BUILD_DIR/fourthassignment
- cd $BUILD_DIR/fifthassignment
- mvn -version
maven_build:
script: mvn verify
\ No newline at end of file
......@@ -21,7 +21,7 @@ public class Application {
public static void main(String[] args) {
char[] input1 = input1 = "[(4+5+1) x (4 / 2)]".toCharArray();
char[] input1 = input1 = "[(4+5+1) x (4 / 2)]".toCharArray();
char[] input2 = "[(4+5+1) x (4 / 2]".toCharArray();
System.out.println(isValid(input1));
System.out.println(isValid(input2));
......
package com.ds.fifthassignment;
//Array implementation of Queue
public class ArrayQueue {
private Object [] data;
private int manyItems;
public ArrayQueue(){
final int INITIAL_CAPACITY = 10;
manyItems=0;
data = new Object[INITIAL_CAPACITY];
}
public ArrayQueue(int initialCapacity){
if(initialCapacity < 0 )
throw new IllegalArgumentException("initialCapacity too small "+initialCapacity);
manyItems = 0;
data = new Object[initialCapacity];
}
public void ensureCapacity(int minimumCapacity){
Object[] biggerArray;
if(data.length < minimumCapacity){
biggerArray = new Object[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
}
}
public int getCapacity(){
return data.length;
}
public boolean isEmpty(){
return (manyItems==0);
}
public Object element(){ //returns the head element in the queue, but does not remove the head element.
if(manyItems ==0)
throw new RuntimeException("QueueUnderflow");
return data[manyItems-1];
}
public Object remove(){
if(manyItems==0) return null;
Object out = data[0];
data = shiftLeft(data);
manyItems--;
return out;
}
public Object[] shiftLeft(Object[] arr) {
int i=0;
for(i=0; i<manyItems-1; i++) {
arr[i] = arr[i+1];
}
arr[manyItems-1] = null;
return arr;
}
public void add (Object item){
if(manyItems == data.length){
ensureCapacity(manyItems*2+1);
}
data[manyItems] = item;
manyItems++;
}
public int size(){ return manyItems; }
public void trimToSize(){
Object[] trimmedArray;
if(data.length != manyItems){
trimmedArray = new Object[manyItems];
System.arraycopy(data, 0, trimmedArray, 0, manyItems);
data = trimmedArray;
}
}
}
\ No newline at end of file
package com.ds.fifthassignment;
import java.util.EmptyStackException;
//Array implementation of Stack
public class ArrayStack {
private Object [] data;
private int manyItems;
public ArrayStack(){
final int INITIAL_CAPACITY = 10;
manyItems=0;
data = new Object[INITIAL_CAPACITY];
}
public ArrayStack(int initialCapacity){
if(initialCapacity < 0 )
throw new IllegalArgumentException("initialCapacity too small "+initialCapacity);
manyItems = 0;
data = new Object[initialCapacity];
}
public void ensureCapacity(int minimumCapacity){
Object[] biggerArray;
if(data.length < minimumCapacity){
biggerArray = new Object[minimumCapacity];
System.arraycopy(data, 0, biggerArray, 0, manyItems);
data = biggerArray;
}
}
public int getCapacity(){
return data.length;
}
public boolean isEmpty(){
return (manyItems==0);
}
public Object peek(){ //returns the top element in the stack, but does not remove that element.
if(manyItems ==0)
throw new EmptyStackException();
return data[manyItems-1];
}
public Object pop(){
if(manyItems==0)
throw new EmptyStackException();
return data[--manyItems];
}
public void push(Object item){
if(manyItems == data.length){
ensureCapacity(manyItems*2+1);
}
data[manyItems] = item;
manyItems++;
}
public int size(){ return manyItems; }
public void trimToSize(){
Object[] trimmedArray;
if(data.length != manyItems){
trimmedArray = new Object[manyItems];
System.arraycopy(data, 0, trimmedArray, 0, manyItems);
data = trimmedArray;
}
}
}
\ No newline at end of file
package com.ds.fifthassignment;
import java.util.Iterator;
import java.util.LinkedList;
public class LinkedListQueue implements Iterable{
//JAVA-LinkedList implementation of Queue.
private LinkedList data;
private Object head;
private Object tail;
public LinkedListQueue() {
data= new LinkedList();
head=null; tail = null;
}
public void add(Object x) {
if(isEmpty()) {
data.add(x); //Appends the specified element to the end (tail) of this list.
tail = data.getLast();
head= tail;
}
else {
data.add(x); //Appends the specified element to the end (tail) of this list.
tail = data.getLast();
}
}
public Object remove() {
if(data.isEmpty()) {
throw new RuntimeException("QueueUnderflow!");
}
else { Object out = head;
data.removeFirst();
if(!data.isEmpty()) head = data.getFirst();
else head = null;
return out;
}
}
public boolean isEmpty() {
return ( head==null ? true : false);
}
public Iterator iterator() {
return data.iterator();
}
}
\ No newline at end of file
package com.ds.fifthassignment;
import java.util.Iterator;
import java.util.LinkedList;
import javax.management.RuntimeErrorException;
public class LinkedListStack implements Iterable{
//JAVA-LinkedList implementation of Stack.
private LinkedList data;
private Object top;
public LinkedListStack() {
data= new LinkedList();
top=null;
}
public void push(Object x) {
data.add(x);
top = data.getLast();
}
public Object pop() {
if(data.isEmpty()) {
throw new RuntimeException("StackUnderflow!");
}
else { Object out = top;
data.removeLast();
if(!data.isEmpty()) top = data.getLast();
else top = null;
return out;
}
}
public boolean isEmpty() {
return ( top==null ? true : false);
}
public Iterator iterator() {
return data.iterator();
}
}
\ No newline at end of file
package com.ds.fifthassignment;
public class Node {
Object data;
Node link;
public Node(Object data , Node link){
this.data = data;
this.link = link;
}
public Object getData() {
return this.data;
}
public Node getNext(){
return this.link;
}
public void setNext(Node link){
this.link = link;
}
public void setData(Integer data){
this.data = data;
}
public boolean hasNext(){
if (link ==null ) return false;
else return true;
}
}
\ No newline at end of file
package com.ds.fifthassignment;
//linkedlist implementation of Queue developed from scratch.
public class Queue {
private Node head;
private Node tail;
public Queue(){
head = null;
tail = null;
}
public boolean isEmpty() { return (head==null)? true : false; }
public void add (Object x){
Node node = new Node(x,null);
if(this.isEmpty()){
tail = node;
tail.setNext(null);
head= tail;
}
else{
tail.setNext(node);
tail = node; //updating the tail
}
}
public Object remove(){
if(this.isEmpty()) return null;
else{
Object out = head.getData();
Node oldHead = head;
head = head.getNext(); //updating the head
oldHead.setNext(null);
oldHead=null;
return out;
}
}
}
\ No newline at end of file
package com.ds.fifthassignment;
//linkedlist implementation of Stack developed from scratch.
public class Stack {
private Node top;
public Stack(){
top = null;
}
public boolean isEmpty() { return (top==null)? true : false; }
public void push(Object x){
Node node = new Node(x,null);
if(this.isEmpty()){
top = node;
top.setNext(null);
}
else{
node.setNext(top);
top = node;
}
}
public Object pop(){
if(this.isEmpty()) return -1;
else{
Object out = top.getData();
Node oldTop = top;
top = top.getNext();
oldTop.setNext(null);
oldTop=null;
return out;
}
}
}
\ No newline at end of file
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