Java writing a method that uses a circular linked list Write

Java writing a method that uses a circular linked list

Write a method that uses a circular (not double) linked list to implement a basic card game. The circular linked list represents the list of players. Each \"round\" cards (the data) are dealt to each player (represented by each index in the list). Whoever is dealt a card with the lowest numerical value loses and is removed from the game. (Kings, queens, etc are not part of this, just cards 1-10). If there is a tie, the entire round is played again. The last player remaining wins. You should output a message to the console indicating which player won and the final card played. The number of players is an input variable. Clearly site any assumptions. You MUST use the provided methods to perform those functions. You may write additional functions if you want. CircularLinkedList - int getSize (); - bool isEmpty()//adds a player to the list, card value is set to 0 - bool add();//Removes the player at the specified location - bool remove lint location); - int dealCard (); Node - int data; - Node next; int playCardGame(int numOfPlayers) {

Solution

import java.util.Scanner;

/* category Node */
class Node
creator */
public Node()
  
/* builder */
public Node(int d,Node n)
  
/* perform to line link to next Node */
public void setLink(Node n)
  
/* perform to line knowledge to current Node */
public void setData(int d)
  
/* perform to urge link to next node */
public Node getLink()
come back link;
}
/* perform to urge knowledge from current Node */
public int getData()
come back data;
}
}

/* category linkedList */
class linkedList
begin ;
protected Node finish ;
public int size ;

/* builder */
public linkedList()
begin = null;
finish = null;
size = 0;
}
/* perform to envision if list is empty */
public mathematician isEmpty()
come back begin == null;
}
/* perform to urge size of the list */
public int getSize()
come back size;
}
/* perform to insert part at the begining */
public void insertAtStart(int val)
{
Node nptr = new Node(val,null);
nptr.setLink(start);
if(start == null)
{
begin = nptr;
nptr.setLink(start);
finish = start;
}
else
{
end.setLink(nptr);
begin = nptr;
}
size++ ;
}
/* perform to insert part at finish */
public void insertAtEnd(int val)
{
Node nptr = new Node(val,null);
nptr.setLink(start);
if(start == null)
{
begin = nptr;
nptr.setLink(start);
finish = start;
}
else
{
end.setLink(nptr);
finish = nptr;
}
size++ ;
}
/* perform to insert part at position */
public void insertAtPos(int val , int pos)
one ;
for (int i = 1; i < size - 1; i++)
  
ptr = ptr.getLink();
}
size++ ;
}
/* perform to delete part at position */
public void deleteAtPos(int pos)
one && pos == 1)
begin = null;
finish = null;
size = 0;
return ;
}
if (pos == 1)
begin = begin.getLink();
end.setLink(start);
size--;
return ;
}
if (pos == size)
whereas (s != end)
  
end = t;
end.setLink(start);
size --;
return;
}
Node ptr = start;
pos = pos - one ;
for (int i = 1; i < size - 1; i++)
  
ptr = ptr.getLink();
}
size-- ;
}
/* perform to show contents */
public void display()
making object of linkedList */
linkedList list = new linkedList();
System.out.println(\"Circular individually coupled List Test\ \");
char ch;
/* Perform list operations */
do
{
System.out.println(\"\ Circular individually coupled List Operations\ \");
System.out.println(\"1. insert at begining\");
System.out.println(\"2. insert at end\");
System.out.println(\"3. insert at position\");
System.out.println(\"4. delete at position\");
System.out.println(\"5. check empty\");
System.out.println(\"6. get size\");
int selection = scan.nextInt();
switch (choice)
  

Java writing a method that uses a circular linked list Write a method that uses a circular (not double) linked list to implement a basic card game. The circular
Java writing a method that uses a circular linked list Write a method that uses a circular (not double) linked list to implement a basic card game. The circular
Java writing a method that uses a circular linked list Write a method that uses a circular (not double) linked list to implement a basic card game. The circular

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site