aakash  patel

aakash patel

  • NA
  • 1
  • 986

Binary Search ADT

Jan 28 2015 5:30 PM

create a Binary Search ADT that implements insertion and search called SortedArray. The SortedArray class, which implements a sorted, one-dimensional array of NHL players and supports binary search, has the following public methods: the SortedArray() constructor, IsEmpty(), Insert() and Find(). You may choose to implement SortedArray as a generic class – if so, the signatures of the various methods will differ.

The public methods of SortedArray() have the following signatures:

public SortedArray(int maxN)

public bool IsEmpty()

public Player Find(Player arg)

Note that this would be

public T Find(T arg)

if you implemented a generic implementation of SortedArray. Note that the argument to Find() is not merely an integer value.

public void Insert(Player arg)

Note that this would be

public void Insert(T arg)

if you followed the generic implementation of SortedArray.

You may NOT change the class name or the signatures of any of these methods in your submission.

You will use each player’s jersey number as the value with which to sort and lookup individual players. For the purposes of this assignment, you may safely assume that all jersey numbers are unique (and you may refrain from using duplicate jersey numbers with your test data). If you choose to implement a generic implementation of SortedArray, then you may only use the CompareTo() method of the Player class with which to compare one Player to another.

Here is the player class(player. cs) file
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NHLPlayer
{
public class Player : IComparable
{
private int Number;
private string PlayerName;
private string Position;
public Player( int newNumber, string newPlayerName, string newPosition )
: base()
{
this.Number = newNumber;
this.PlayerName = newPlayerName;
this.Position = newPosition;
}
public int Priority()
{
return this.Number;
}
public int getNumber()
{
return this.Number;
}
public string getPlayerName()
{
return this.PlayerName;
}
public string getPosition()
{
return this.Position;
}
public int CompareTo( Object obj )
{
if (obj == null) return 1;
Player otherPlayer = obj as Player;
if (otherPlayer != null)
return this.CompareTo( otherPlayer );
else
throw new ArgumentException( "Object is not a Player" );
}
public int CompareTo( Player other )
{
if (other == null) throw new ArgumentNullException();
if (this.Priority() < other.Priority()) return -1;
else if (this.Priority() > other.Priority()) return 1;
else return 0;
}
public override int GetHashCode()
{
return this.Priority();
}
public bool Equals( Player other )
{
if (other == null)
return false;
if (this.Number == other.Number)
return true;
else
return false;
}
public override bool Equals( Object obj )
{
if (obj == null)
return false;
Player x = obj as Player;
if (x == null)
return false;
else
return Equals( x );
}
public static bool operator ==( Player player1, Player player2 )
{
if ((object)player1 == null || ((object)player2) == null)
return Object.Equals( player1, player2 );
return player1.Equals( player2 );
}
public static bool operator !=( Player player1, Player player2 )
{
if (player1 == null || player2 == null)
return !Object.Equals( player1, player2 );
return !(player1.Equals( player2 ));
}
}
}