Removing Duplicates Inside Insertion Sort

前端 未结 2 1242
渐次进展
渐次进展 2021-01-07 06:20

\"enter

I am basically dealing with the following problem where i am trying to alter t

2条回答
  •  一向
    一向 (楼主)
    2021-01-07 07:03

    public void InsertSort()
    {
        int t, j;
        for (int i = 1; i < _leght; i++)
        {
           t = _arr[i];
           for (j = i; j > 0; )
           {
                if (_arr[j - 1] == t) t = -1;
                if (_arr[j - 1] > t)
                {
                      _arr[j] = _arr[j - 1];
                      j--;
                 }
                 else break;
            }
            _arr[j] = t;
         }
    }
    

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题