Error 1: an index with [] cannot be applied to the expression C:/Inetpub/wwwroot/StrigDs/Form5.cs 39 13 StrigDs of the "StrigDs. SeqList <T>" type.
Error:
SqList [0] = key; // This sentence is incorrect ????????????
Program:
Public class SeqList <T>
{
Public SeqList <T> sqList;
Public SeqList <T> GetLength ()
{
Return sqList. GetLength ();
}
Public int BinarySearch (SeqList <T> sqList, int key)
{
SqList [0] = key; // store the record to be searched
Int mid = 0;
Int flag =-1; // flag
Int low = 1; // set the lower limit of the initial interval
Int high = Convert. ToInt32 (sqList. GetLength (); // you can specify the upper limit of the initial interval.
// The record is not found.
While (low <= high)
{
// Middle
Mid = (low + high)/2;
If (sqList [0] = sqList [mid])
{
Flag = mid; // search successful, then save record to flag's
Break;
}
Else if (sqList [0] <sqList [mid])
{// Left binary Area
High = mid-1;
}
Else
{// Right binary Area
Low = Mid + 1;
}
}
If (flag> 0)
{
Console. writeline ("search is successful ");
Return flag;
}
Else
{
Console. writeline ("search is failed ");
Return-1;
}
}
}