Skip to content
Snippets Groups Projects
Commit 134b1b2f authored by pm3g19's avatar pm3g19
Browse files

Deleted/untracked unneeded files.

parent a1d69e4b
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 227 deletions
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Debug (Launch)-Main<src_311626d8>",
"request": "launch",
"mainClass": "Main",
"projectName": "src_311626d8"
},
{
"type": "java",
"name": "Debug (Launch)-TestMain<src_311626d8>",
"request": "launch",
"mainClass": "TestMain",
"projectName": "src_311626d8"
}
]
}
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"mainClass": "${file}"
},
{
"type": "java",
"name": "Debug (Launch)-TestMain<test_5834f569>",
"request": "launch",
"mainClass": "TestMain",
"projectName": "test_5834f569"
}
]
}
\ No newline at end of file
public abstract class Action {
enum Type {CHANGE_CELL_VALUE, CLEAR_BOARD, SAMPLE};
private Type type;
private boolean flipped = false;
public Action(Type type) {
this.type = type;
}
public Type getType() {
return type;
}
public boolean isFlipped() {
return flipped;
}
public void reverse() {
flipped = !flipped;
}
}
public class LimitedStack<T> implements LimitedStackBase<T> {
final int maxSize;
int size = 0;
int head = 0;
T[] data;
public LimitedStack(LimitedStack<T> other) {
this(other.maxSize);
this.size = other.size;
this.head = other.head;
System.arraycopy(other.data, 0, data, 0, maxSize);
}
public LimitedStack(int maxSize) {
this.maxSize = maxSize;
data = (T[])new Object[maxSize];
}
@Override
public void push(T item) {
if (isFull()) {
head = loop(head, 1);
size--;
}
data[loop(head, size)] = item;
size++;
}
public T popHead() {
assert (!isEmpty());
T a = data[head];
size--;
head = loop(head, 1);
return a;
}
/*@Override
public void push(Action item, int pos) {
}*/
@Override
public T pop() {
assert(!isEmpty());
T item = data[loop(head, size - 1)];
size--;
return item;
}
@Override
public boolean isEmpty() {
return size == 0;
}
public T[] toArray() {
T[] arr = (T[]) new Object[size];
for (int i = 0; i < size; i ++) {
arr[i] = data[loop(head, i)];
}
return arr;
}
@Override
public boolean isFull() {
return size == maxSize;
}
private int loop(int index,int offset) {
return (index + offset) % maxSize;
}
@Override
public void clear() {
size = 0;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append('[');
for (int i = 0; i < size; i++) {
sb.append(data[loop(head, i)]);
sb.append(", ");
}
sb.append(']');
return sb.toString();
}
}
public interface LimitedStackBase<E> {
/**
* Pushes item at the end
*/
void push(E item);
//void push(E item, int pos);
E pop();
boolean isEmpty();
boolean isFull();
E popHead();
void clear();
}
public class SampleAction extends Action {
String message;
public SampleAction(String message) {
super(Type.SAMPLE);
this.message = message;
}
@Override
public String toString() {
return message;
}
}
public class TestMain {
public static void main(String[] args) {
LimitedStack stack = new LimitedStack(3);
stack.push(new SampleAction("aardvark"));
stack.push(new SampleAction("pig"));
stack.push(new SampleAction("dog"));
stack.push(new SampleAction("sheep"));
stack.push(new SampleAction("wolf"));
stack.push(new SampleAction("horse"));
Action temp = stack.pop();
temp = stack.pop();
temp = stack.pop();
}
}
public abstract class Action {
enum Type {CHANGE_CELL_VALUE, CLEAR_BOARD, SAMPLE};
private Type type;
private boolean flipped = false;
public Action(Type type) {
this.type = type;
}
public Type getType() {
return type;
}
public boolean isFlipped() {
return flipped;
}
public void reverse() {
flipped = !flipped;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment