public class SeqList<int>   // 此句错误 ??
    {
        public SeqList<int> sqList;
        public int getLength()
        {
            sqList.getLength();  
        }        public int BinarySearch(SeqList<int> sqList, int key)
        {
            sqList[0] = key; //存放要查找的记录
            int mid = 0;
            int flag = -1;// 标志
            int low = 1; //设置初始区间的下限值
            int high = sqList.getLength(); // 设置初始区间的上限值            //记录没有查找完
            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;
            }        }
}
错误 1 类型参数声明必须是标识符,不能是类型 C:\Inetpub\wwwroot\StrigDs\StrigDs\Form2.cs 73 26 StrigDs
public class SeqList<int>   // 此句错误 ??

解决方案 »

  1.   

    对. 泛型在声明的时候不要指定类型public class SeqList <T>
      

  2.   


    public class SeqList <T>  
        { 
            public SeqList <T> sqList; 
            public int getLength() 
            { 
                sqList.getLength();  
            }         public int BinarySearch(SeqList <T> sqList, int key) 
            { 
                sqList[0] = key; //存放要查找的记录 
                int mid = 0; 
                int flag = -1;// 标志 
                int low = 1; //设置初始区间的下限值 
                int high = sqList.getLength(); // 设置初始区间的上限值             //记录没有查找完 
                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; 
                }         } 

      

  3.   

    错误 1 无法将带 [] 的索引应用于“StrigDs.SeqList <T>”类型的表达式 C:\Inetpub\wwwroot\StrigDs\StrigDs\Form5.cs 39 13 StrigDs 
    Error : 
      sqList[0] = key; //此句错误???????????? 
      
    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; //存放要查找的记录 
                int mid = 0; 
                int flag = -1;// 标志 
                int low = 1; //设置初始区间的下限值 
                int high = Convert.ToInt32(sqList.GetLength()); // 设置初始区间的上限值             //记录没有查找完 
                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; 
                }         } 
        }