Skip to content

Commit

Permalink
Set Project: All Classes Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
13howardD committed Apr 28, 2015
1 parent 716c014 commit e1ea4f9
Showing 1 changed file with 96 additions and 52 deletions.
148 changes: 96 additions & 52 deletions src/Table.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,120 @@
public class Table{
public class Table {
private TableNode head;
private int length;

public Table(){
public Table() {
head = null;
length = 0;
}

public void add(Card c1){
TableNode tempNode = new TableNode(c1);
tempNode.setNext(head);
head = tempNode;
public void add(Card card) {
TableNode Node1 = new TableNode(card);
Node1.setNext(head);
head = Node1;
}

public void removeSet(Card c1, Card c2, Card c3){
TableNode curr = head;
if (c1.isSet(c2, c3) == false){
public void removeSet(Card c1, Card c2, Card c3) {
if (c1.isSet(c2, c3) == false) {
return;
}
else if (c1.isSet(c2, c3)){

c1 = null;
c2 = null;
c2 = null;

else {
Card remove1 = null;
Card remove2 = null;
Card remove3 = null;

TableNode temp = head;

while (temp != null) {
if (c1.equals(temp.getCard()))
remove1 = c1;

if (c2.equals(temp.getCard()))
remove2 = c2;

if (c3.equals(temp.getCard()))
remove3 = c3;

temp = temp.getNext();
}

if (remove1 != null && remove2 != null && remove3 != null) {
TableNode curr = head;
TableNode prev = null;

while (curr != null) {

if (c1.equals(curr.getCard()) || c2.equals(curr.getCard()) || c3.equals(curr.getCard())) {
if (curr == head) {
curr = curr.getNext();
head = head.getNext();
}
else {
prev.setNext(curr.getNext());
curr = curr.getNext();
}
}
else {
prev = curr;
curr = curr.getNext();
}
}
}
}
else{
return;
}

public int numCards() {
TableNode currNode = head;
int count = 0;
while (currNode != null) {
count += 1;
currNode = currNode.getNext();
}
return count;
}

public int numCards(){
TableNode curr = head;
int cardCount = 0;
public Card getCard(int index) {
if (index > numCards() - 1) {
return null;
}

if (curr == null){
return 0;
TableNode temp = head;
if (temp == null) {
return null;
}
else{

while (curr != null){
curr = curr.getNext();
cardCount += 1;
else {
for (int i = 0; i < index; i++) {
temp = temp.getNext();
}
return temp.getCard();
}
return cardCount;
}
}

public Card getCard(int index){
TableNode curr = head;

if (curr == null){
return null;
}
else{
for (int i = 0; i < index; i++){
curr = curr.getNext();
public int numSets() {
int count = 0;
if (numCards() < 3) {
return 0;
}
}
else {
TableNode n1 = head;
while (n1 != null && n1.getNext().getNext() != null) {
TableNode n2 = n1.getNext();

while (n2 != null && n2.getNext() != null) {
TableNode n3 = n2.getNext();

while (n3 != null) {
if (n3.getCard().isSet(n2.getCard(), n1.getCard()) == true) {
count += 1;
}
n3 = n3.getNext();
}
n2 = n2.getNext();
}
n1 = n1.getNext();

return curr.getCard();
}
return count;
}
}


public int numSets(){
TableNode curr = head;
TableNode curr2 = curr.getNext();
TableNode curr3 = curr2.getNext();
int setCount = 0;
if (curr.getCard().isSet(curr2.getCard(), curr3.getCard()) == true){
setCount +=1;
}
return setCount;
}
}

0 comments on commit e1ea4f9

Please sign in to comment.