Linked Lists Method Question (need help) [code provided]

Anonymous
timer Asked: Jul 2nd, 2013
account_balance_wallet $5

Question Description

Hey guys, below is a piece of code. Underneath that is what I am trying to accomplish with my code, but am confused on what to do. Can someone please help?

public class PlayerLinkedList extends ShellLinkedList
{

  public PlayerLinkedList(  )
  {
  super( );
  }

  public void insert( Player p )
  {
  // insert as head
  PlayerNode pn = new PlayerNode( new Player(  p ) );
  pn.setNext( head );
  head = pn;
  numberOfItems++;
  }

  public Player delete( int searchID )
  throws DataStructureException
  {
  PlayerNode current = head;
  PlayerNode previous = null;
  while ( current != null
  && current.getPlayer( ).getID( ) != searchID )
  {
  previous = current;
  current = current.getNext( );
  }

  if ( current == null ) // not found
  throw new DataStructureException( searchID
  + " not found: cannot be deleted" );
  else
  {
  if ( current == head )
  head = head.getNext( );  // delete head
  else
  previous.setNext( current.getNext( ) );

  numberOfItems--;
  return current.getPlayer( );
  }
  }

 
  public Player peek( int searchID )
  throws DataStructureException
  {
  PlayerNode current = head;
  while ( current != null
  && current.getPlayer( ).getID( ) != searchID )
  {
  current = current.getNext( );
  }

  if ( current == null ) // not found
  throw new DataStructureException( searchID
  + " not found: cannot be deleted" );
  else
  {
  return current.getPlayer( );
  }
  }
}


I want to include one more method that inserts a new player in the third position of the list. Head would be the first position. If the list is empty, the method will insert the new player as the head of the list.

Can anyone please help me with this? I would really appreciate it.

Tutor Answer

khakaan
School: UT Austin

You should ask your programming questions at likeplum. I always get good answers there to my programming issues and questions. Especially about php, js or html questions…They have programmers online to help you asap. It's free.

https://www.likeplum.com/user/learn/programming/aid/2

flag Report DMCA
Review

Anonymous
Good stuff. Would use again.

Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors